Skip to content

Commit 0b0f8ab

Browse files
committed
Add autocommit setting to connect HiveServer2 with impyla
1 parent 7e9633b commit 0b0f8ab

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ to specify it in the connection string::
150150

151151
mysql+pymysql://scott:tiger@localhost/foo?charset=utf8
152152

153+
Note that ``impala`` connecion with `impyla`_ for HiveServer2 requires to disable autocommit::
154+
155+
%config SqlMagic.autocommit=False
156+
%sql impala://hserverhost:port/default?kerberos_service_name=hive&auth_mechanism=GSSAPI
157+
158+
.. _impyla: https://github.com/cloudera/impyla
159+
153160
Configuration
154161
-------------
155162

@@ -165,6 +172,9 @@ only the screen display is truncated.
165172
In [2]: %config SqlMagic
166173
SqlMagic options
167174
--------------
175+
SqlMagic.autocommit=<Bool>
176+
Current: True
177+
Set autocommit mode
168178
SqlMagic.autolimit=<Int>
169179
Current: 0
170180
Automatically limit the size of the returned result sets

src/sql/magic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class SqlMagic(Magics, Configurable):
3636
"When the first argument is of the form [section], "
3737
"a sqlalchemy connection string is formed from the "
3838
"matching section in the DSN file.")
39+
autocommit = Bool(True, config=True, help="Set autocommit mode")
3940

4041

4142
def __init__(self, shell):

src/sql/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def run(conn, sql, config, user_namespace):
276276
result = conn.session.execute(txt, user_namespace)
277277
try:
278278
# mssql has autocommit
279-
if 'mssql' not in str(conn.dialect):
279+
if 'mssql' not in str(conn.dialect) and config.autocommit:
280280
conn.session.execute('commit')
281281
except sqlalchemy.exc.OperationalError:
282282
pass # not all engines can commit

0 commit comments

Comments
 (0)