Repository navigation
Conversation
ClickHouse rejects a column comment on a dictionary (Code 48, NOT_IMPLEMENTED; seen on 25.8, 26.3 and 26.10), and the adapter sends every comment in one ALTER, so persist_docs with columns: true failed the whole dictionary model. The dictionary materialization now persists only the relation's comment.
A dictionary model has to list its structure in the `fields` config, next to the YAML columns that document the same names and types, and the two lists drift apart. With an enforced contract and no `fields`, the structure is now the model's YAML columns and their data_type, in their order, as a table's DDL is. An enforced contract is now also checked for a dictionary that reads the model's query, with or without `fields`, so a contracted dictionary whose YAML columns do not match its query fails, as a table does. A YAML column without data_type fails with dbt's own error; a model with neither `fields` nor a contract fails with a message that says so instead of "'NoneType' object is not iterable".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #765. Builds on #766 (column comments on dictionaries): until that merges, this diff also shows its commit.
A
dictionarymodel declares its structure twice: in thefieldsconfig, and in its YAMLcolumns, where the same names and types are documented and tested. Nothing compares the two, so they drift apart without an error. This PR lets the YAML be the single source when the model has an enforced contract, as it already is for a table:contract: {enforced: true}and nofields, the dictionary structure is the model's YAML columns and theirdata_type, in their order.fieldsworks as before and takes precedence when set.clickhousesource withouttable), with or withoutfields,get_assert_columns_equivalent(sql)compares that query with the YAML columns, as in the table, view and incremental materializations, and fails on a missing, extra or differently typed column. A dictionary that reads atableor anhttpsource has no query to compare, so nothing is checked there.+contract) was never checked; it is now, so a YAML that does not list every query column with its exact type fails.data_typefails with dbt'sColumnTypeMissingError(exceptions.column_type_missing). Without the check the DDL would getname None.fieldsnor a contract, the model fails with a compile error that names both options, instead of'NoneType' object is not iterable.{{ config(materialized='dictionary', primary_key='id', layout='HASHED()', lifetime='MIN 0 MAX 300') }} select id, name from {{ source('raw', 'people') }}The dbt Core 2.0 ClickHouse adapter (#660; dictionary parity #706) would need the same behaviour.
Tested:
pytest tests -k "dictionary or persist_docs or PersistDocs"against a single-node ClickHouse in Docker (25.8, 26.3 and 26.10.2.103), HTTP driver: 17 passed, 1 skipped (TestHttpDictionaryneedsDBT_CH_TEST_INCLUDE_S3); the new tests fail on the parent commit, and thetable-source test fails when thetable/httpguard is removed.make lintpasses. Not run: theDistributed*and replicated-database tests, which need a cluster.Checklist
ColumnTypeMissingErrorfor a column withoutdata_type. Integration tests: a contracted dictionary built from its YAML columns; a query whose type differs from the YAML failing the contract; atable-source dictionary that is not compared with the placeholder query; a model with neitherfieldsnor a contract failing with the new message. The seven new tests fail on the parent commit and pass here.docswas updated with further explanations or tutorialsNote
Medium Risk
Enforced-contract dictionaries backed by model SQL are newly validated against the query; previously unchecked projects may fail on the next run. Behavior change is intentional governance, not runtime data risk.
Overview
Dictionary models with an enforced contract can now omit the
fieldsconfig: structure is derived from YAMLcolumnsand theirdata_type(in order), matching table behavior. Settingfieldsstill wins when present.When the contract is enforced and the source is the model SQL (default ClickHouse source, not
tableorhttp), the adapter runsget_assert_columns_equivalenton the query vs YAML—so existing contracted dictionaries may start failing if columns drift. Withoutfieldsor a contract, compile fails with a clear message instead of aNoneTypeiteration error; YAML columns missingdata_typeraisecolumn_type_missing.persist_docson dictionary materializations now passesfor_columns=false, so relation docs apply but column comments are skipped (ClickHouse rejects column comments on dictionaries).Reviewed by Cursor Bugbot for commit c25ff73. Bugbot is set up for automated code reviews on this repo. Configure here.