Skip to content

Commit 4405c72

Browse files
authored
Chore!: Bump sqlglot to 20.8.0 (#1938)
1 parent 11272e4 commit 4405c72

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"requests",
4848
"rich[jupyter]",
4949
"ruamel.yaml",
50-
"sqlglot[rs]~=20.7.1",
50+
"sqlglot[rs]~=20.8.0",
5151
],
5252
extras_require={
5353
"bigquery": [

tests/core/engine_adapter/test_mssql.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_columns(make_mocked_engine_adapter: t.Callable):
7373
}
7474

7575
adapter.cursor.execute.assert_called_once_with(
76-
"""SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "numeric_scale" FROM "information_schema"."columns" WHERE "table_name" = 'table' AND "table_schema" = 'db';"""
76+
"""SELECT [column_name], [data_type], [character_maximum_length], [numeric_precision], [numeric_scale] FROM [information_schema].[columns] WHERE [table_name] = 'table' AND [table_schema] = 'db';"""
7777
)
7878

7979

@@ -84,8 +84,8 @@ def test_table_exists(make_mocked_engine_adapter: t.Callable):
8484
resp = adapter.table_exists("db.table")
8585
adapter.cursor.execute.assert_called_once_with(
8686
"""SELECT 1 """
87-
"""FROM "information_schema"."tables" """
88-
"""WHERE "table_name" = 'table' AND "table_schema" = 'db';"""
87+
"""FROM [information_schema].[tables] """
88+
"""WHERE [table_name] = 'table' AND [table_schema] = 'db';"""
8989
)
9090
assert resp
9191
adapter.cursor.fetchone.return_value = None
@@ -118,9 +118,9 @@ def test_insert_overwrite_by_time_partition_supports_insert_overwrite_pandas(
118118
f"__temp_test_table_{temp_table_id}", [(1, "2022-01-01"), (2, "2022-01-02")]
119119
)
120120
assert to_sql_calls(adapter) == [
121-
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE "__temp_test_table_{temp_table_id}" ("a" INTEGER, "ds" VARCHAR(MAX))');""",
122-
f"""MERGE INTO "test_table" AS "__MERGE_TARGET__" USING (SELECT "a" AS "a", "ds" AS "ds" FROM (SELECT CAST("a" AS INTEGER) AS "a", CAST("ds" AS VARCHAR(MAX)) AS "ds" FROM "__temp_test_table_{temp_table_id}") AS "_subquery" WHERE "ds" BETWEEN '2022-01-01' AND '2022-01-02') AS "__MERGE_SOURCE__" ON (1 = 0) WHEN NOT MATCHED BY SOURCE AND "ds" BETWEEN '2022-01-01' AND '2022-01-02' THEN DELETE WHEN NOT MATCHED THEN INSERT ("a", "ds") VALUES ("a", "ds");""",
123-
f'DROP TABLE IF EXISTS "__temp_test_table_{temp_table_id}";',
121+
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE [__temp_test_table_{temp_table_id}] ([a] INTEGER, [ds] VARCHAR(MAX))');""",
122+
f"""MERGE INTO [test_table] AS [__MERGE_TARGET__] USING (SELECT [a] AS [a], [ds] AS [ds] FROM (SELECT CAST([a] AS INTEGER) AS [a], CAST([ds] AS VARCHAR(MAX)) AS [ds] FROM [__temp_test_table_{temp_table_id}]) AS [_subquery] WHERE [ds] BETWEEN '2022-01-01' AND '2022-01-02') AS [__MERGE_SOURCE__] ON (1 = 0) WHEN NOT MATCHED BY SOURCE AND [ds] BETWEEN '2022-01-01' AND '2022-01-02' THEN DELETE WHEN NOT MATCHED THEN INSERT ([a], [ds]) VALUES ([a], [ds]);""",
123+
f"DROP TABLE IF EXISTS [__temp_test_table_{temp_table_id}];",
124124
]
125125

126126

@@ -150,9 +150,9 @@ def test_insert_overwrite_by_time_partition_replace_where_pandas(
150150
)
151151

152152
assert to_sql_calls(adapter) == [
153-
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE "__temp_test_table_{temp_table_id}" ("a" INTEGER, "ds" VARCHAR(MAX))');""",
154-
f"""MERGE INTO "test_table" AS "__MERGE_TARGET__" USING (SELECT "a" AS "a", "ds" AS "ds" FROM (SELECT CAST("a" AS INTEGER) AS "a", CAST("ds" AS VARCHAR(MAX)) AS "ds" FROM "__temp_test_table_{temp_table_id}") AS "_subquery" WHERE "ds" BETWEEN '2022-01-01' AND '2022-01-02') AS "__MERGE_SOURCE__" ON (1 = 0) WHEN NOT MATCHED BY SOURCE AND "ds" BETWEEN '2022-01-01' AND '2022-01-02' THEN DELETE WHEN NOT MATCHED THEN INSERT ("a", "ds") VALUES ("a", "ds");""",
155-
f'DROP TABLE IF EXISTS "__temp_test_table_{temp_table_id}";',
153+
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE [__temp_test_table_{temp_table_id}] ([a] INTEGER, [ds] VARCHAR(MAX))');""",
154+
f"""MERGE INTO [test_table] AS [__MERGE_TARGET__] USING (SELECT [a] AS [a], [ds] AS [ds] FROM (SELECT CAST([a] AS INTEGER) AS [a], CAST([ds] AS VARCHAR(MAX)) AS [ds] FROM [__temp_test_table_{temp_table_id}]) AS [_subquery] WHERE [ds] BETWEEN '2022-01-01' AND '2022-01-02') AS [__MERGE_SOURCE__] ON (1 = 0) WHEN NOT MATCHED BY SOURCE AND [ds] BETWEEN '2022-01-01' AND '2022-01-02' THEN DELETE WHEN NOT MATCHED THEN INSERT ([a], [ds]) VALUES ([a], [ds]);""",
155+
f"DROP TABLE IF EXISTS [__temp_test_table_{temp_table_id}];",
156156
]
157157

158158

@@ -180,9 +180,9 @@ def test_insert_append_pandas(
180180
)
181181

182182
assert to_sql_calls(adapter) == [
183-
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE "__temp_test_table_{temp_table_id}" ("a" INTEGER, "b" INTEGER)');""",
184-
f'INSERT INTO "test_table" ("a", "b") SELECT CAST("a" AS INTEGER) AS "a", CAST("b" AS INTEGER) AS "b" FROM "__temp_test_table_{temp_table_id}";',
185-
f'DROP TABLE IF EXISTS "__temp_test_table_{temp_table_id}";',
183+
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE [__temp_test_table_{temp_table_id}] ([a] INTEGER, [b] INTEGER)');""",
184+
f"INSERT INTO [test_table] ([a], [b]) SELECT CAST([a] AS INTEGER) AS [a], CAST([b] AS INTEGER) AS [b] FROM [__temp_test_table_{temp_table_id}];",
185+
f"DROP TABLE IF EXISTS [__temp_test_table_{temp_table_id}];",
186186
]
187187

188188

@@ -196,7 +196,7 @@ def test_create_table(make_mocked_engine_adapter: t.Callable):
196196
adapter.create_table("test_table", columns_to_types)
197197

198198
adapter.cursor.execute.assert_called_once_with(
199-
"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'test_table') EXEC('CREATE TABLE "test_table" ("cola" INTEGER, "colb" VARCHAR(MAX))');"""
199+
"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'test_table') EXEC('CREATE TABLE [test_table] ([cola] INTEGER, [colb] VARCHAR(MAX))');"""
200200
)
201201

202202

@@ -215,7 +215,7 @@ def test_create_table_properties(make_mocked_engine_adapter: t.Callable):
215215
)
216216

217217
adapter.cursor.execute.assert_called_once_with(
218-
"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'test_table') EXEC('CREATE TABLE "test_table" ("cola" INTEGER, "colb" VARCHAR(MAX))');"""
218+
"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'test_table') EXEC('CREATE TABLE [test_table] ([cola] INTEGER, [colb] VARCHAR(MAX))');"""
219219
)
220220

221221

@@ -245,9 +245,9 @@ def test_merge_pandas(
245245
)
246246

247247
assert to_sql_calls(adapter) == [
248-
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_target_{temp_table_id}') EXEC('CREATE TABLE "__temp_target_{temp_table_id}" ("id" INTEGER, "ts" DATETIME2, "val" INTEGER)');""",
249-
f'MERGE INTO "target" AS "__MERGE_TARGET__" USING (SELECT CAST("id" AS INTEGER) AS "id", CAST("ts" AS DATETIME2) AS "ts", CAST("val" AS INTEGER) AS "val" FROM "__temp_target_{temp_table_id}") AS "__MERGE_SOURCE__" ON "__MERGE_TARGET__"."id" = "__MERGE_SOURCE__"."id" WHEN MATCHED THEN UPDATE SET "__MERGE_TARGET__"."id" = "__MERGE_SOURCE__"."id", "__MERGE_TARGET__"."ts" = "__MERGE_SOURCE__"."ts", "__MERGE_TARGET__"."val" = "__MERGE_SOURCE__"."val" WHEN NOT MATCHED THEN INSERT ("id", "ts", "val") VALUES ("__MERGE_SOURCE__"."id", "__MERGE_SOURCE__"."ts", "__MERGE_SOURCE__"."val");',
250-
f'DROP TABLE IF EXISTS "__temp_target_{temp_table_id}";',
248+
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_target_{temp_table_id}') EXEC('CREATE TABLE [__temp_target_{temp_table_id}] ([id] INTEGER, [ts] DATETIME2, [val] INTEGER)');""",
249+
f"MERGE INTO [target] AS [__MERGE_TARGET__] USING (SELECT CAST([id] AS INTEGER) AS [id], CAST([ts] AS DATETIME2) AS [ts], CAST([val] AS INTEGER) AS [val] FROM [__temp_target_{temp_table_id}]) AS [__MERGE_SOURCE__] ON [__MERGE_TARGET__].[id] = [__MERGE_SOURCE__].[id] WHEN MATCHED THEN UPDATE SET [__MERGE_TARGET__].[id] = [__MERGE_SOURCE__].[id], [__MERGE_TARGET__].[ts] = [__MERGE_SOURCE__].[ts], [__MERGE_TARGET__].[val] = [__MERGE_SOURCE__].[val] WHEN NOT MATCHED THEN INSERT ([id], [ts], [val]) VALUES ([__MERGE_SOURCE__].[id], [__MERGE_SOURCE__].[ts], [__MERGE_SOURCE__].[val]);",
250+
f"DROP TABLE IF EXISTS [__temp_target_{temp_table_id}];",
251251
]
252252

253253
adapter.cursor.reset_mock()
@@ -268,9 +268,9 @@ def test_merge_pandas(
268268
)
269269

270270
assert to_sql_calls(adapter) == [
271-
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_target_{temp_table_id}') EXEC('CREATE TABLE "__temp_target_{temp_table_id}" ("id" INTEGER, "ts" DATETIME2, "val" INTEGER)');""",
272-
f'MERGE INTO "target" AS "__MERGE_TARGET__" USING (SELECT CAST("id" AS INTEGER) AS "id", CAST("ts" AS DATETIME2) AS "ts", CAST("val" AS INTEGER) AS "val" FROM "__temp_target_{temp_table_id}") AS "__MERGE_SOURCE__" ON "__MERGE_TARGET__"."id" = "__MERGE_SOURCE__"."id" AND "__MERGE_TARGET__"."ts" = "__MERGE_SOURCE__"."ts" WHEN MATCHED THEN UPDATE SET "__MERGE_TARGET__"."id" = "__MERGE_SOURCE__"."id", "__MERGE_TARGET__"."ts" = "__MERGE_SOURCE__"."ts", "__MERGE_TARGET__"."val" = "__MERGE_SOURCE__"."val" WHEN NOT MATCHED THEN INSERT ("id", "ts", "val") VALUES ("__MERGE_SOURCE__"."id", "__MERGE_SOURCE__"."ts", "__MERGE_SOURCE__"."val");',
273-
f'DROP TABLE IF EXISTS "__temp_target_{temp_table_id}";',
271+
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_target_{temp_table_id}') EXEC('CREATE TABLE [__temp_target_{temp_table_id}] ([id] INTEGER, [ts] DATETIME2, [val] INTEGER)');""",
272+
f"MERGE INTO [target] AS [__MERGE_TARGET__] USING (SELECT CAST([id] AS INTEGER) AS [id], CAST([ts] AS DATETIME2) AS [ts], CAST([val] AS INTEGER) AS [val] FROM [__temp_target_{temp_table_id}]) AS [__MERGE_SOURCE__] ON [__MERGE_TARGET__].[id] = [__MERGE_SOURCE__].[id] AND [__MERGE_TARGET__].[ts] = [__MERGE_SOURCE__].[ts] WHEN MATCHED THEN UPDATE SET [__MERGE_TARGET__].[id] = [__MERGE_SOURCE__].[id], [__MERGE_TARGET__].[ts] = [__MERGE_SOURCE__].[ts], [__MERGE_TARGET__].[val] = [__MERGE_SOURCE__].[val] WHEN NOT MATCHED THEN INSERT ([id], [ts], [val]) VALUES ([__MERGE_SOURCE__].[id], [__MERGE_SOURCE__].[ts], [__MERGE_SOURCE__].[val]);",
273+
f"DROP TABLE IF EXISTS [__temp_target_{temp_table_id}];",
274274
]
275275

276276

@@ -280,9 +280,9 @@ def test_replace_query(make_mocked_engine_adapter: t.Callable):
280280
adapter.replace_query("test_table", parse_one("SELECT a FROM tbl"), {"a": "int"})
281281

282282
assert to_sql_calls(adapter) == [
283-
"""SELECT 1 FROM "information_schema"."tables" WHERE "table_name" = 'test_table';""",
284-
'TRUNCATE TABLE "test_table"',
285-
'INSERT INTO "test_table" ("a") SELECT "a" FROM "tbl";',
283+
"""SELECT 1 FROM [information_schema].[tables] WHERE [table_name] = 'test_table';""",
284+
"TRUNCATE TABLE [test_table]",
285+
"INSERT INTO [test_table] ([a]) SELECT [a] FROM [tbl];",
286286
]
287287

288288

@@ -307,11 +307,11 @@ def test_replace_query_pandas(
307307
)
308308

309309
assert to_sql_calls(adapter) == [
310-
"""SELECT 1 FROM "information_schema"."tables" WHERE "table_name" = 'test_table';""",
311-
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE "__temp_test_table_{temp_table_id}" ("a" INTEGER, "b" INTEGER)');""",
312-
'TRUNCATE TABLE "test_table"',
313-
f'INSERT INTO "test_table" ("a", "b") SELECT CAST("a" AS INTEGER) AS "a", CAST("b" AS INTEGER) AS "b" FROM "__temp_test_table_{temp_table_id}";',
314-
f'DROP TABLE IF EXISTS "__temp_test_table_{temp_table_id}";',
310+
"""SELECT 1 FROM [information_schema].[tables] WHERE [table_name] = 'test_table';""",
311+
f"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = '__temp_test_table_{temp_table_id}') EXEC('CREATE TABLE [__temp_test_table_{temp_table_id}] ([a] INTEGER, [b] INTEGER)');""",
312+
"TRUNCATE TABLE [test_table]",
313+
f"INSERT INTO [test_table] ([a], [b]) SELECT CAST([a] AS INTEGER) AS [a], CAST([b] AS INTEGER) AS [b] FROM [__temp_test_table_{temp_table_id}];",
314+
f"DROP TABLE IF EXISTS [__temp_test_table_{temp_table_id}];",
315315
]
316316

317317

@@ -325,7 +325,7 @@ def test_create_table_primary_key(make_mocked_engine_adapter: t.Callable):
325325
adapter.create_table("test_table", columns_to_types, primary_key=("cola", "colb"))
326326

327327
adapter.cursor.execute.assert_called_once_with(
328-
"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'test_table') EXEC('CREATE TABLE "test_table" ("cola" INTEGER, "colb" VARCHAR(MAX), PRIMARY KEY ("cola", "colb"))');"""
328+
"""IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'test_table') EXEC('CREATE TABLE [test_table] ([cola] INTEGER, [colb] VARCHAR(MAX), PRIMARY KEY ([cola], [colb]))');"""
329329
)
330330

331331

@@ -335,7 +335,7 @@ def test_create_index(make_mocked_engine_adapter: t.Callable):
335335

336336
adapter.create_index("test_table", "test_index", ("cola", "colb"))
337337
adapter.cursor.execute.assert_called_once_with(
338-
"""IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = object_id('test_table') AND name = 'test_index') EXEC('CREATE INDEX "test_index" ON "test_table"("cola", "colb")');"""
338+
"""IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = object_id('test_table') AND name = 'test_index') EXEC('CREATE INDEX [test_index] ON [test_table]([cola], [colb])');"""
339339
)
340340

341341

@@ -347,9 +347,9 @@ def test_drop_schema_with_catalog(make_mocked_engine_adapter: t.Callable, mocker
347347
adapter.drop_schema("catalog.schema")
348348

349349
assert to_sql_calls(adapter) == [
350-
'USE "catalog";',
351-
'DROP SCHEMA IF EXISTS "schema";',
352-
'USE "other_catalog";',
350+
"USE [catalog];",
351+
"DROP SCHEMA IF EXISTS [schema];",
352+
"USE [other_catalog];",
353353
]
354354

355355

@@ -382,7 +382,7 @@ def set_local_catalog(catalog, local_state):
382382
]
383383

384384
assert to_sql_calls(adapter) == [
385-
'USE "test_catalog";',
385+
"USE [test_catalog];",
386386
"""
387387
SELECT
388388
'test_catalog' AS catalog_name,
@@ -392,7 +392,7 @@ def set_local_catalog(catalog, local_state):
392392
FROM INFORMATION_SCHEMA.TABLES
393393
WHERE TABLE_SCHEMA LIKE '%test_schema%'
394394
""",
395-
'USE "other_catalog";',
395+
"USE [other_catalog];",
396396
]
397397

398398

@@ -412,8 +412,8 @@ def test_drop_schema(make_mocked_engine_adapter: t.Callable):
412412
adapter.drop_schema("test_schema", cascade=True)
413413

414414
assert to_sql_calls(adapter) == [
415-
"""DROP VIEW IF EXISTS "test_schema"."test_view";""",
416-
"""DROP SCHEMA IF EXISTS "test_schema";""",
415+
"""DROP VIEW IF EXISTS [test_schema].[test_view];""",
416+
"""DROP SCHEMA IF EXISTS [test_schema];""",
417417
]
418418

419419

0 commit comments

Comments
 (0)