Closed Giganoide01 closed 3 months ago
this is now fixed in sqlglot v23.8.2
https://github.com/tobymao/sqlglot/commit/281db61009ee01d10690dcc1f2039062b2a1a58c
in general, i wouldn't recommend doing fully qualified column names as you've done and use aliases, but you are right that it should work so this has been fixed.
with the other issue regarding the schema / type for self references, this is a restriction of models that do self referencing. in order to have a model self reference, we need to be able to create the table statically. we can't create a self reference table with a CTAS query because it doesn't exist yet.
i'll document this / add an error. (https://github.com/TobikoData/sqlmesh/pull/2419/files)
I'm facing an issue implementing a self-referenced incremental model.
The model receives an external table, with defined types for its columns, and makes a left join with itself. But it's not capable of finding its runtime-generated table.
Environment Versions
Steps to replicate
gateways: local: connection: type: duckdb database: db.db
default_gateway: local
model_defaults: dialect: duckdb
MODEL ( name abcd.incremental_model, kind INCREMENTAL_BY_TIME_RANGE ( time_column event_date ), start '2024-01-01', cron '@daily', );
select mock_data.input_table.id, mock_data.input_table.event_date, abcd.incremental_model.event_date as previous_event_date from mock_data.input_table left join abcd.incremental_model on mock_data.input_table.id = abcd.incremental_model.id
run
sqlmesh plan dev
. You should get an error like this:to correct this behavior, add an alias to abcd.incremental_model and specify the type of the incoming column in models/incremental_model.sql, as shown below:
select mock_data.input_table.id, mock_data.input_table.event_date, processed_table.event_date::TEXT as previous_event_date from mock_data.input_table left join abcd.incremental_model as processed_table on mock_data.input_table.id = processed_table.id