ClickHouse / ClickHouse/dbt-clickhouse

FixedString(N) contract columns always fail with "data type mismatch"

Open
#726 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
362
Forks
177
Avg merge
2d 10h
Merged PRs (30d)
8

Description

## Description

`ClickHouseColumn.data_type` renders every string-family type as `String`, discarding the size (`string_type()` ignores its argument). Two symptoms, one cause:

1. **Contract `FixedString(N)` fails:** the contract check compares `column.data_type` verbatim against the YAML `data_type`, so `FixedString(64)` vs. rendered `String` → "data type mismatch".
2. **Contract `String` passes, then incremental breaks:** the check passes (`String` == `String`), the table is created with a `String` column while the model produces `FixedString(N)`, and subsequent runs fail with:
```
The source and target schemas on this incremental model are out of sync.
...
New column types: ['my_col String']
```
The drift detection (raw dtype comparison) is correct, but the message renders the new type through `data_type`, so it claims the new type is `String` while the table column already is `String`.

## Reproduction

```sql
-- models/my_model.sql
{{ config(materialized='incremental', on_schema_change='fail') }}
select toFixedString('abc', 64) as my_col
```
```yaml
# models/schema.yml
version: 2
models:
- name: my_model
config:
contract:
enforced: true
columns:
- name: my_col
data_type: String # run 1 ok, run 2 fails above; FixedString(64) fails run 1
```

## Expected behavior

A `FixedString(N)` contract matches a `FixedString(N)` column; a `String` contract does not silently pass against one; the schema-change error shows the actual type.

## Environment

dbt-clickhouse 1.10.2, dbt-core 1.9–1.12

Contributor guide

Open the contributing guide

Research direction

Start by locating ClickHouseColumn.data_type, string_type(), the contract data-type comparison, and the incremental schema-drift message described in the issue. Reproduce the two cases with the supplied SQL and YAML, then run the relevant test suite. Done means FixedString(N) is preserved and matched correctly, String does not match it silently, and schema-change errors show the actual type.

Written by the indexing model from the issue text.

Assessment

Tech stack
clickhouse, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.