Skip to content

fix: emit CREATE VIEW when model type is view in SQL export (#1031)#1119

Open
barry0451 wants to merge 1 commit intodatacontract:mainfrom
barry0451:fix/issue-1031-sql-view-export
Open

fix: emit CREATE VIEW when model type is view in SQL export (#1031)#1119
barry0451 wants to merge 1 commit intodatacontract:mainfrom
barry0451:fix/issue-1031-sql-view-export

Conversation

@barry0451
Copy link
Copy Markdown
Contributor

Fixes #1031

When a model has type: view in the data contract YAML, the SQL exporter was unconditionally emitting CREATE TABLE. This change makes the exporter emit CREATE VIEW (or CREATE OR REPLACE VIEW for Databricks) when the model's physicalType is view, matching the behavior of the dbt exporter.

Changes:

  • In _to_sql_table(), check model.physicalType.lower() == 'view' and swap the DDL keyword accordingly
  • Databricks uses CREATE OR REPLACE VIEW to align with Databricks best practices
  • All column definitions, NOT NULL, PRIMARY KEY, and COMMENT clauses are preserved

Test:

  • Added test_to_sql_ddl_postgres_view() with a dedicated view-based fixture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export SQL DDL driven by schema.physicalType : view (CREATE VIEW) default is table (CREATE TABLE)

1 participant