Skip to content

Commit e3d02bd

Browse files
authored
feat(impala): add tbl_properties to create_table (#9839)
`TBLPROPERTIES` can be set on table creation. Exposing this lets us un-xfail a few tests by setting the required `TBLPROPERTIES` to make them work.
1 parent c573392 commit e3d02bd

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

ibis/backends/impala/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def create_table(
471471
format="parquet",
472472
location=None,
473473
partition=None,
474+
tbl_properties: Mapping[str, Any] | None = None,
474475
like_parquet=None,
475476
) -> ir.Table:
476477
"""Create a new table using an Ibis table expression or in-memory data.
@@ -501,6 +502,8 @@ def create_table(
501502
partition
502503
Must pass a schema to use this. Cannot partition from an
503504
expression.
505+
tbl_properties
506+
Table properties to set on table creation.
504507
like_parquet
505508
Can specify instead of a schema
506509
@@ -534,6 +537,7 @@ def create_table(
534537
format=format,
535538
external=True if location is not None else external,
536539
partition=partition,
540+
tbl_properties=tbl_properties,
537541
path=location,
538542
)
539543
)
@@ -549,6 +553,7 @@ def create_table(
549553
external=external,
550554
path=location,
551555
partition=partition,
556+
tbl_properties=tbl_properties,
552557
)
553558
)
554559
return self.table(name, database=database or self.current_database)

ibis/backends/impala/ddl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ def _create_line(self):
105105
def _location(self):
106106
return f"LOCATION '{self.path}'" if self.path else None
107107

108+
def _tbl_properties(self):
109+
return (
110+
self.format_tblproperties(self.tbl_properties)
111+
if self.tbl_properties
112+
else None
113+
)
114+
108115
def _storage(self):
109116
# By the time we're here, we have a valid format
110117
return f"STORED AS {self.format}"
@@ -152,6 +159,7 @@ def _pieces(self):
152159
yield self._storage()
153160

154161
yield self._location()
162+
yield self._tbl_properties()
155163

156164

157165
class AlterTable(ImpalaBase, DDL):
@@ -258,6 +266,7 @@ def __init__(
258266
can_exist=False,
259267
path=None,
260268
partition=None,
269+
tbl_properties=None,
261270
):
262271
super().__init__(
263272
table_name,
@@ -267,6 +276,7 @@ def __init__(
267276
can_exist=can_exist,
268277
path=path,
269278
partition=partition,
279+
tbl_properties=tbl_properties,
270280
)
271281
self.select = select
272282

@@ -275,6 +285,7 @@ def _pieces(self):
275285
yield self._partitioned_by()
276286
yield self._storage()
277287
yield self._location()
288+
yield self._tbl_properties()
278289
yield "AS"
279290
yield self.select
280291

ibis/backends/impala/tests/test_partition.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pandas as pd
66
import pandas.testing as tm
77
import pytest
8-
from impala.error import HiveServer2Error
98

109
import ibis
1110
from ibis import util
@@ -142,10 +141,14 @@ def test_create_partitioned_table_from_expr(con, alltypes, tmp_parted):
142141
tm.assert_frame_equal(result, expected)
143142

144143

145-
@pytest.mark.xfail(raises=HiveServer2Error)
146144
def test_add_drop_partition_no_location(con, temp_table):
147145
schema = ibis.schema([("foo", "string"), ("year", "int32"), ("month", "int16")])
148-
con.create_table(temp_table, schema=schema, partition=["year", "month"])
146+
con.create_table(
147+
temp_table,
148+
schema=schema,
149+
partition=["year", "month"],
150+
tbl_properties={"transactional": "false"},
151+
)
149152
table = con.table(temp_table)
150153

151154
part = {"year": 2007, "month": 4}
@@ -159,10 +162,14 @@ def test_add_drop_partition_no_location(con, temp_table):
159162
assert len(table.partitions()) == 1
160163

161164

162-
@pytest.mark.xfail(raises=HiveServer2Error)
163165
def test_add_drop_partition_owned_by_impala(con, temp_table):
164166
schema = ibis.schema([("foo", "string"), ("year", "int32"), ("month", "int16")])
165-
con.create_table(temp_table, schema=schema, partition=["year", "month"])
167+
con.create_table(
168+
temp_table,
169+
schema=schema,
170+
partition=["year", "month"],
171+
tbl_properties={"transactional": "false"},
172+
)
166173

167174
table = con.table(temp_table)
168175

@@ -181,10 +188,14 @@ def test_add_drop_partition_owned_by_impala(con, temp_table):
181188
assert len(table.partitions()) == 1
182189

183190

184-
@pytest.mark.xfail(raises=HiveServer2Error)
185191
def test_add_drop_partition_hive_bug(con, temp_table):
186192
schema = ibis.schema([("foo", "string"), ("year", "int32"), ("month", "int16")])
187-
con.create_table(temp_table, schema=schema, partition=["year", "month"])
193+
con.create_table(
194+
temp_table,
195+
schema=schema,
196+
partition=["year", "month"],
197+
tbl_properties={"transactional": "false"},
198+
)
188199

189200
table = con.table(temp_table)
190201

0 commit comments

Comments
 (0)