You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 91ea5eb
Browse filesBrowse the repository at this point in the historyBrowse files
fix(redshift): address review feedback on late-binding CTAS fallback
- Raise SQLMeshError in VarcharSizeWorkaroundMixin when the temp view's
column types are unavailable, instead of creating the table from the
LIMIT 0 CTAS with non-deterministic VARCHAR widths (Redshift and MSSQL).
- Order BasePostgresEngineAdapter.columns() by attnum so the pg_catalog
fallback preserves the view's SELECT order.
- Document why Redshift's exists=True path does not forward target types
and pin view-derived VARCHAR widths with a test.
- Schema-qualify late-binding view sources in the test fixtures.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Vamsi-klu <nrvamsi13@gmail.com>
withpytest.raises(SQLMeshError, match="Could not determine column types"):
994
+
adapter.ctas(
995
+
table_name="sqlmesh_xxx.my_example",
996
+
query_or_df=parse_one(
997
+
"SELECT id, updated_at, trashed_at, CAST(NULL AS TIMESTAMP) AS valid_from, CAST(NULL AS TIMESTAMP) AS valid_to FROM sqlmesh_xxx.my_table WHERE FALSE LIMIT 0"
998
+
),
999
+
exists=False,
1000
+
)
1001
+
1002
+
# The table must never be created from the LIMIT 0 CTAS (VARCHAR widths are non-deterministic)
1003
+
# and the temp view must still be cleaned up.
1004
+
assertto_sql_calls(adapter) == [
1005
+
'CREATE VIEW "__temp_ctas_test_random_id" AS SELECT "id", "updated_at", "trashed_at", CAST(NULL AS TIMESTAMP) AS "valid_from", CAST(NULL AS TIMESTAMP) AS "valid_to" FROM "sqlmesh_xxx"."my_table" WITH NO SCHEMA BINDING',
1006
+
'DROP VIEW IF EXISTS "__temp_ctas_test_random_id" CASCADE',
'CREATE VIEW "__temp_ctas_test_random_id" AS SELECT "id", "updated_at", "trashed_at", CAST(NULL AS TIMESTAMP) AS "valid_from", CAST(NULL AS TIMESTAMP) AS "valid_to" FROM "my_table" WITH NO SCHEMA BINDING',
1047
+
'CREATE VIEW "__temp_ctas_test_random_id" AS SELECT "id", "name" FROM "sqlmesh_xxx"."my_table" WITH NO SCHEMA BINDING',
1006
1048
'DROP VIEW IF EXISTS "__temp_ctas_test_random_id" CASCADE',
1007
-
'CREATE TABLE "sqlmesh_xxx"."my_example" AS SELECT "id", "updated_at", "trashed_at", CAST(NULL AS TIMESTAMP) AS "valid_from", CAST(NULL AS TIMESTAMP) AS "valid_to" FROM "my_table" WHERE FALSE LIMIT 0',
# creating the table from the LIMIT 0 CTAS, which can truncate VARCHARs or lose the schema
1185
1229
adapter.cursor.execute.reset_mock()
1186
1230
adapter.cursor.fetchall.side_effect= [[], [], []]
1187
-
strategy.create(
1188
-
table_name=target_table,
1189
-
model=model,
1190
-
is_table_deployable=True,
1191
-
render_kwargs={},
1192
-
skip_grants=True,
1193
-
)
1231
+
withpytest.raises(SQLMeshError, match="Could not determine column types"):
1232
+
strategy.create(
1233
+
table_name=target_table,
1234
+
model=model,
1235
+
is_table_deployable=True,
1236
+
render_kwargs={},
1237
+
skip_grants=True,
1238
+
)
1194
1239
create_calls_fallback=to_sql_calls(adapter)
1195
-
asserttruncated_ddlnotincreate_calls_fallback
1196
-
assert (
1197
-
'CREATE TABLE "sqlmesh__sqlmesh_xxx"."sqlmesh_xxx__my_example__1234567890" AS SELECT "id" AS "id", "updated_at" AS "updated_at", "trashed_at" AS "trashed_at", CAST(NULL AS TIMESTAMP) AS "valid_from", CAST(NULL AS TIMESTAMP) AS "valid_to" FROM "my_table" AS "my_table" WHERE FALSE LIMIT 0'
'CREATE TABLE "s"."t" AS SELECT "id" AS "id", "val" AS "val", CAST(NULL AS TIMESTAMP) AS "valid_from", CAST(NULL AS TIMESTAMP) AS "valid_to" FROM "src" AS "src" WHERE FALSE LIMIT 0'
1508
-
increate_calls
1509
-
)
1539
+
withpytest.raises(SQLMeshError, match="Could not determine column types"):
0 commit comments