22
33import pytest
44from pytest_mock .plugin import MockerFixture
5- from sqlglot import exp
5+ from sqlglot import exp , parse_one
66
77from sqlmesh .core .engine_adapter import TrinoEngineAdapter
88from tests .core .engine_adapter import to_sql_calls
@@ -73,8 +73,11 @@ def test_partitioned_by_hive(
7373
7474 adapter .create_table ("test_table" , columns_to_types , partitioned_by = [exp .to_column ("colb" )])
7575
76+ adapter .ctas ("test_table" , parse_one ("select 1" ), partitioned_by = [exp .to_column ("colb" )]) # type: ignore
77+
7678 assert to_sql_calls (adapter ) == [
77- """CREATE TABLE IF NOT EXISTS "test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONED_BY=ARRAY['colb'])"""
79+ """CREATE TABLE IF NOT EXISTS "test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONED_BY=ARRAY['colb'])""" ,
80+ """CREATE TABLE IF NOT EXISTS "test_table" WITH (PARTITIONED_BY=ARRAY['colb']) AS SELECT 1""" ,
7881 ]
7982
8083
@@ -96,8 +99,11 @@ def test_partitioned_by_iceberg(
9699
97100 adapter .create_table ("test_table" , columns_to_types , partitioned_by = [exp .to_column ("colb" )])
98101
102+ adapter .ctas ("test_table" , parse_one ("select 1" ), partitioned_by = [exp .to_column ("colb" )]) # type: ignore
103+
99104 assert to_sql_calls (adapter ) == [
100- """CREATE TABLE IF NOT EXISTS "test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONING=ARRAY['colb'])"""
105+ """CREATE TABLE IF NOT EXISTS "test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONING=ARRAY['colb'])""" ,
106+ """CREATE TABLE IF NOT EXISTS "test_table" WITH (PARTITIONING=ARRAY['colb']) AS SELECT 1""" ,
101107 ]
102108
103109
@@ -122,8 +128,15 @@ def test_partitioned_by_iceberg_transforms(
122128 partitioned_by = [exp .to_column ("day(cola)" ), exp .to_column ("truncate(colb, 8)" )],
123129 )
124130
131+ adapter .ctas (
132+ "test_table" ,
133+ parse_one ("select 1" ), # type: ignore
134+ partitioned_by = [exp .to_column ("day(cola)" ), exp .to_column ("truncate(colb, 8)" )],
135+ )
136+
125137 assert to_sql_calls (adapter ) == [
126- """CREATE TABLE IF NOT EXISTS "test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONING=ARRAY['day(cola)', 'truncate(colb, 8)'])"""
138+ """CREATE TABLE IF NOT EXISTS "test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONING=ARRAY['day(cola)', 'truncate(colb, 8)'])""" ,
139+ """CREATE TABLE IF NOT EXISTS "test_table" WITH (PARTITIONING=ARRAY['day(cola)', 'truncate(colb, 8)']) AS SELECT 1""" ,
127140 ]
128141
129142
@@ -141,13 +154,27 @@ def test_partitioned_by_with_multiple_catalogs_same_server(
141154 "datalake.test_schema.test_table" , columns_to_types , partitioned_by = [exp .to_column ("colb" )]
142155 )
143156
157+ adapter .ctas (
158+ "datalake.test_schema.test_table" ,
159+ parse_one ("select 1" ), # type: ignore
160+ partitioned_by = [exp .to_column ("colb" )],
161+ )
162+
144163 adapter .create_table (
145164 "datalake_iceberg.test_schema.test_table" ,
146165 columns_to_types ,
147166 partitioned_by = [exp .to_column ("colb" )],
148167 )
149168
169+ adapter .ctas (
170+ "datalake_iceberg.test_schema.test_table" ,
171+ parse_one ("select 1" ), # type: ignore
172+ partitioned_by = [exp .to_column ("colb" )],
173+ )
174+
150175 assert to_sql_calls (adapter ) == [
151176 """CREATE TABLE IF NOT EXISTS "datalake"."test_schema"."test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONED_BY=ARRAY['colb'])""" ,
177+ """CREATE TABLE IF NOT EXISTS "datalake"."test_schema"."test_table" WITH (PARTITIONED_BY=ARRAY['colb']) AS SELECT 1""" ,
152178 """CREATE TABLE IF NOT EXISTS "datalake_iceberg"."test_schema"."test_table" ("cola" INTEGER, "colb" VARCHAR) WITH (PARTITIONING=ARRAY['colb'])""" ,
179+ """CREATE TABLE IF NOT EXISTS "datalake_iceberg"."test_schema"."test_table" WITH (PARTITIONING=ARRAY['colb']) AS SELECT 1""" ,
153180 ]
0 commit comments