|
38 | 38 | SqlModel, |
39 | 39 | TimeColumn, |
40 | 40 | ExternalKind, |
| 41 | + ViewKind, |
41 | 42 | create_external_model, |
42 | 43 | create_seed_model, |
43 | 44 | create_sql_model, |
@@ -6091,3 +6092,48 @@ def test_cluster_with_complex_expression(): |
6091 | 6092 |
|
6092 | 6093 | model = load_sql_based_model(expressions) |
6093 | 6094 | assert [expr.sql("snowflake") for expr in model.clustered_by] == ['(TO_DATE("CLUSTER_COL"))'] |
| 6095 | + |
| 6096 | + |
| 6097 | +def test_parametric_model_kind(tmp_path: Path): |
| 6098 | + init_example_project(tmp_path, dialect="duckdb") |
| 6099 | + |
| 6100 | + test_sql_file = tmp_path / "models/test_model.sql" |
| 6101 | + test_sql_file.write_text( |
| 6102 | + """ |
| 6103 | + MODEL ( |
| 6104 | + name test_schema.test_model, |
| 6105 | + kind @IF(@gateway = 'main', VIEW, FULL) |
| 6106 | + ); |
| 6107 | +
|
| 6108 | + SELECT |
| 6109 | + 1 AS c |
| 6110 | + """ |
| 6111 | + ) |
| 6112 | + |
| 6113 | + db_path = str(tmp_path / "db.db") |
| 6114 | + config = Config( |
| 6115 | + gateways={ |
| 6116 | + "main": GatewayConfig(connection=DuckDBConnectionConfig(database=db_path)), |
| 6117 | + "other": GatewayConfig(connection=DuckDBConnectionConfig(database=db_path)), |
| 6118 | + }, |
| 6119 | + model_defaults=ModelDefaultsConfig(dialect="duckdb"), |
| 6120 | + ) |
| 6121 | + |
| 6122 | + context = Context(paths=tmp_path, config=config) |
| 6123 | + plan = context.plan(no_prompts=True, auto_apply=True, no_diff=True) |
| 6124 | + |
| 6125 | + assert len(plan.context_diff.new_snapshots) == 4 |
| 6126 | + assert isinstance(context.get_model("test_schema.test_model").kind, ViewKind) |
| 6127 | + |
| 6128 | + context = Context(paths=tmp_path, config=config, gateway="other") |
| 6129 | + plan = context.plan(no_prompts=True, auto_apply=True, no_diff=True) |
| 6130 | + diff = plan.context_diff |
| 6131 | + |
| 6132 | + assert len(diff.new_snapshots) == 1 |
| 6133 | + assert len(diff.modified_snapshots) == 1 |
| 6134 | + |
| 6135 | + new_snapshot, old_snapshot = next(iter(diff.modified_snapshots.values())) |
| 6136 | + assert isinstance(t.cast(SqlModel, new_snapshot.node).kind, FullKind) |
| 6137 | + assert isinstance(t.cast(SqlModel, old_snapshot.node).kind, ViewKind) |
| 6138 | + |
| 6139 | + assert isinstance(context.get_model("test_schema.test_model").kind, FullKind) |
0 commit comments