Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add a new column to incremental model that is also a unique_key #322

Closed
the4thamigo-uk opened this issue Jul 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@the4thamigo-uk
Copy link
Contributor

If I create an incremental model, and then add a column which is also added to the unique_key, the model fails to build with the error :

DB::Exception: Missing columns: 'col_3' while processing query: 'SELECT col_1, col_2 FROM dbt_clickhouse_2760_test_schema_change_1721300786653.schema_change_append WHERE (col_1, col_3) NOT IN ((SELECT col_1, col_3 FROM dbt_clickhouse_2760_test_schema_change_1721300786653.schema_change_append__dbt_new_data) AS _subquery18)', required columns: 'col_1' 'col_2' 'col_3', maybe you meant: 'col_1' or 'col_2'. (UNKNOWN_IDENTIFIER) (version 23.6.2.18 (official build))

It seems to be failing when trying to insert the records from the old table that are not in the new_data table.

See related PR for unit test that demonstrates the issue: https://github.com/the4thamigo-uk/dbt-clickhouse/pull/1/files

I wonder though, how this could be fixed?

One way would be to modify the query as indicated :

SELECT   col_1,   col_2 
FROM 
  dbt_clickhouse_2760_test_schema_change_1721300786653.schema_change_append 
WHERE 
    (
      col_1,
      col_3  <--- REMOVE THE NEW UNIQUE KEY COLUMN
    ) NOT IN (
    (
      SELECT
        col_1,
        col_3   <--- REMOVE THE NEW UNIQUE KEY COLUMN
      FROM 
        dbt_clickhouse_2760_test_schema_change_1721300786653.schema_change_append__dbt_new_data
    ) AS _subquery18
  )

Do you think this approach is viable/correct?

Additionally: I notice that for schema changes the strategy switches to the legacy approach, is there scope to implement this using delete+insert?

@the4thamigo-uk the4thamigo-uk added the bug Something isn't working label Jul 18, 2024
the4thamigo-uk pushed a commit to the4thamigo-uk/dbt-clickhouse that referenced this issue Jul 18, 2024
the4thamigo-uk pushed a commit to the4thamigo-uk/dbt-clickhouse that referenced this issue Jul 18, 2024
@BentsiLeviav
Copy link
Contributor

Fixed by #332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants