20 changes: 13 additions & 7 deletions ibis/backends/impala/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def insert(
partition_schema=partition_schema,
overwrite=overwrite,
)
return self._client.raw_sql(statement.compile())
self._client._safe_exec_sql(statement.compile())
return self

def load_data(self, path, overwrite=False, partition=None):
"""Load data into an Impala table.
Expand Down Expand Up @@ -333,7 +334,8 @@ def load_data(self, path, overwrite=False, partition=None):
overwrite=overwrite,
)

return self._client.raw_sql(stmt.compile())
self._client._safe_exec_sql(stmt.compile())
return self

@property
def name(self):
Expand All @@ -348,7 +350,7 @@ def rename(self, new_name, database=None):
if not m and database is None:
database = self._database
statement = RenameTable(self._qualified_name, new_name, new_database=database)
self._client.raw_sql(statement)
self._client._safe_exec_sql(statement)

op = self.op().copy(name=statement.new_qualified_name)
return type(self)(op)
Expand Down Expand Up @@ -385,7 +387,8 @@ def add_partition(self, spec, location=None):
stmt = ddl.AddPartition(
self._qualified_name, spec, part_schema, location=location
)
return self._client.raw_sql(stmt)
self._client._safe_exec_sql(stmt)
return self

def alter(
self,
Expand All @@ -410,7 +413,8 @@ def alter(

def _run_ddl(**kwds):
stmt = AlterTable(self._qualified_name, **kwds)
return self._client.raw_sql(stmt)
self._client._safe_exec_sql(stmt)
return self

return self._alter_table_helper(
_run_ddl,
Expand Down Expand Up @@ -451,7 +455,8 @@ def alter_partition(

def _run_ddl(**kwds):
stmt = ddl.AlterPartition(self._qualified_name, spec, part_schema, **kwds)
return self._client.raw_sql(stmt)
self._client._safe_exec_sql(stmt)
return self

return self._alter_table_helper(
_run_ddl,
Expand All @@ -474,7 +479,8 @@ def drop_partition(self, spec):
"""Drop an existing table partition."""
part_schema = self.partition_schema()
stmt = ddl.DropPartition(self._qualified_name, spec, part_schema)
return self._client.raw_sql(stmt)
self._client._safe_exec_sql(stmt)
return self

def partitions(self):
"""Return information about the table's partitions.
Expand Down
3 changes: 2 additions & 1 deletion ibis/backends/impala/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def mockcon():
@pytest.fixture(scope="module")
def kudu_table(con, test_data_db):
name = 'kudu_backed_table'
con.raw_sql(
cur = con.raw_sql(
f"""\
CREATE TABLE {test_data_db}.{name} (
a STRING,
Expand All @@ -408,6 +408,7 @@ def kudu_table(con, test_data_db):
'kudu.num_tablet_replicas' = '1'
)"""
)
cur.close()
yield con.table(name)
con.drop_table(name, database=test_data_db)

Expand Down
14 changes: 4 additions & 10 deletions ibis/backends/impala/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from contextlib import closing
from posixpath import join as pjoin

import pandas as pd
Expand All @@ -25,12 +26,6 @@ def test_hdfs_connect_function_is_public():
assert hasattr(ibis.impala, "hdfs_connect")


def test_cursor_garbage_collection(con):
for _ in range(5):
con.raw_sql('select 1').fetchall()
con.raw_sql('select 1').fetchone()


def test_raise_ibis_error_no_hdfs(con_no_hdfs):
# GH299
with pytest.raises(com.IbisError):
Expand Down Expand Up @@ -62,9 +57,8 @@ def test_sql_with_limit(con):

def test_raw_sql(con):
query = 'SELECT * from functional_alltypes limit 10'
cur = con.raw_sql(query)
rows = cur.fetchall()
cur.release()
with closing(con.raw_sql(query)) as cur:
rows = cur.fetchall()
assert len(rows) == 10


Expand Down Expand Up @@ -295,7 +289,7 @@ def test_datetime_to_int_cast(con):

def test_set_option_with_dot(con):
con.set_options({'request_pool': 'baz.quux'})
result = dict(row[:2] for row in con.raw_sql('set').fetchall())
result = con.get_options()
assert result['REQUEST_POOL'] == 'baz.quux'


Expand Down
10 changes: 7 additions & 3 deletions ibis/backends/impala/tests/test_ddl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from contextlib import closing
from posixpath import join as pjoin

import pytest
Expand Down Expand Up @@ -346,13 +347,16 @@ def test_query_delimited_file_directory(con, test_data_dir, tmp_db):
@pytest.fixture
def temp_char_table(con):
name = "testing_varchar_support"
con.raw_sql(
f"""\
with closing(
con.raw_sql(
f"""\
CREATE TABLE IF NOT EXISTS {name} (
group1 VARCHAR(10),
group2 CHAR(10)
)"""
)
)
):
pass
assert name in con.list_tables(), name
yield con.table(name)
con.drop_table(name, force=True)
Expand Down