Repository navigation
Export a schema with physicalType: view as a view in SQL DDL - #1732
Conversation
|
Producing a view without the proper joins does not feel that helpful. It is not a correct view. Why not use AI for this, which can even suggest a way of joining the columns? /cc @jschoedl |
The relationship and references will be implemented soon, at this state the export is enough for my needs. |
|
Thanks @simonharrer, fair point: a view with a cross join isn't a correct view. I'd rather not call an LLM from
It will also accept column references in AI suggesting joins when there are no relationships sounds useful, maybe in |
|
relationships does not help, as this only is for the tables of the data contract, not for the source tables. I still see this as an issue. We typically create valid things via export. Here, we create something that is obviously flawed. People will not expect this. They are REQUIRED to improve it manually. So what is the gain? We could generate the view, but add a placeholder in the view that makes it unexecutable so a user has to fix it. Then, I am okay with it. But it should not just work without the join column. Or simply comment the FROM out, and one has to comment it in afterwards. Something like this. |
|
I agree with Simon: ODCS has no place for a full join specification (yet), and we should rather make this limitation obvious than guess during the export. For specific company-internal conventions, it can in general be more helpful to use a custom exporter, as you @dmaresma shared here. The native exporters in @OGsiji Could you limit the PR to views with a single source object? If there are several known source objects, you may generate a non-executable draft, which could look like this: CREATE OR REPLACE VIEW orders_enriched AS
SELECT
order_id,
customer_id,
customer_name
FROM bronze.orders
JOIN bronze.customers ON <TODO: join condition>;and similar with |
30d9aec to
52b3689
Compare
|
Makes sense, thanks @jschoedl and @simonharrer. Pushed that:
The draft cases also log a warning. I dropped the relationships join and the fallback to a table, and rebased on main. |
A description such as `The customer's orders.` ended the COMMENT string of a Snowflake view early. It is now escaped as on tables.
SQL Server requires CREATE VIEW to be the first statement of a batch, so a contract with a table before a view, or with two views, failed with error 111. The export now puts GO before and after each view.
Each source of a draft view gets an alias, the last part of its name (orders_2 on a clash), and each column that comes from a single source is prefixed with it. Filling in the join condition is then enough to create the view; before, a column present in several sources, usually the join key, stayed ambiguous.
The warning now reads: Schema 'orders_enriched' is a view with 2 source objects, which cannot be exported safely. Please replace the TODOs in the exported SQL.
|
Thank you for the revision! I went over it and added a few changes on top. It's mostly small stuff like comments and warning message changes, but one notable change: In the draft for multi-source views, I added table aliases. This allows to use the template by changing only one line. As an example, this is what a user needs to manually change now: CREATE OR REPLACE VIEW orders_enriched AS
SELECT
orders.order_id,
orders.customer_id,
customers.customer_name
FROM bronze.orders orders
-JOIN bronze.customers customers ON <TODO: join condition>;
+JOIN bronze.customers customers ON orders.customer_id = customers.customer_id;and those were the manual changes needed before my commit: CREATE OR REPLACE VIEW orders_enriched AS
SELECT
order_id,
- customer_id,
+ bronze.orders.customer_id,
customer_name
FROM bronze.orders
-JOIN bronze.customers ON <TODO: join condition>;
+JOIN bronze.customers ON bronze.orders.customer_id = bronze.customers.customer_id; |
…export # Conflicts: # CHANGELOG.md

Closes #1031.
A schema with
physicalType: viewnow exports asCREATE OR REPLACE VIEW … AS SELECT …instead ofCREATE TABLE. Column types and the primary key are left out.transformSourceObjects. An entry whose last part is the property's name, such asbronze.orders.order_id, is read as a column of that object.JOIN bronze.customers ON <TODO: join condition>. With none, it selectsFROM <TODO: source object>. Both log a warning, and the view cannot be created until the TODOs are filled in.CREATE OR ALTER VIEW.