Skip to content

Commit 0e29b88

Browse files
authored
Allow sqlglot 30.18 and later (#1702)
* Allow sqlglot 30.18 and later sqlglot 30.18 renamed Drop's `this` argument to `tables` and silently ignores the old name, so ibis 12 renders nameless DROP statements (e.g. the temporary view behind Table.sql on Hive, or DuckDB create_table from a DataFrame). Map `this` to `tables` until ibis 13 is the minimum. * Keep ibis's DROP names with compiled sqlglot and test --filter on Postgres * Remove changelog entry for the sqlglot pin
1 parent 9493d1b commit 0e29b88

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sqlglot.expressions as sge
2+
from sqlglot.dialects.tsql import TSQL
3+
from sqlglot.generator import Generator
4+
5+
# sqlglot 30.18 renamed Drop's `this` to `tables`; ibis 12 still passes `this`. Remove once ibis 13 is the floor.
6+
# Patches the generators, not Drop.__init__, which compiled sqlglot (sqlglotc) never calls.
7+
if "this" not in sge.Drop.arg_types:
8+
for generator in (Generator, TSQL.Generator):
9+
10+
def _drop_sql_with_this(self, expression, _drop_sql=generator.drop_sql):
11+
if expression.args.get("this") and not expression.args.get("tables"):
12+
expression = expression.copy()
13+
expression.set("tables", [expression.args.pop("this")])
14+
return _drop_sql(self, expression)
15+
16+
generator.drop_sql = _drop_sql_with_this

‎pyproject.toml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ dependencies = [
6060
"pytz>=2024.1",
6161
"python-multipart>=0.0.20,<1.0.0",
6262
"rich>=13.7,<16.0",
63-
# below 30.18 until an issue in ibis is fixed - see https://github.com/datacontract/datacontract-cli/issues/1592
64-
"sqlglot>=26.6.0,<30.18",
63+
"sqlglot>=26.6.0,<31.0.0",
6564
"python-dotenv>=1.0.0,<2.0.0",
6665
"boto3>=1.34.41,<2.0.0",
6766
"Jinja2>=3.1.5,<4.0.0",

‎tests/test_test_postgres.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ def test_test_postgres_odcs_postgresql_server_type(postgres_container, monkeypat
7272
assert all(check.result == "passed" for check in run.checks)
7373

7474

75+
def test_test_postgres_odcs_filter(postgres_container, monkeypatch):
76+
monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username)
77+
monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password)
78+
_init_sql("fixtures/postgres/data/data.sql")
79+
80+
data_contract_str = _setup_datacontract("fixtures/postgres/odcs.yaml")
81+
run = DataContract(data_contract_str=data_contract_str, filter="field_two > 40").test()
82+
83+
print(run.pretty())
84+
assert run.result == "passed"
85+
assert all(check.result == "passed" for check in run.checks)
86+
87+
7588
def test_test_postgres_case_sensitive_table_name(postgres_container, monkeypatch):
7689
monkeypatch.setenv("DATACONTRACT_POSTGRES_USERNAME", postgres.username)
7790
monkeypatch.setenv("DATACONTRACT_POSTGRES_PASSWORD", postgres.password)

0 commit comments

Comments
 (0)