Skip to content

feat: Allow INDEX syntax sugar for projections with _part_offset#651

Open
29antonioac wants to merge 3 commits into
ClickHouse:mainfrom
29antonioac:feat/index-syntax-projections
Open

feat: Allow INDEX syntax sugar for projections with _part_offset#651
29antonioac wants to merge 3 commits into
ClickHouse:mainfrom
29antonioac:feat/index-syntax-projections

Conversation

@29antonioac

@29antonioac 29antonioac commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add index parameter to projections model config to allow setting index projections nicer.
  • Using ADD PROJECTION my_projection INDEX my, columns TYPE basic if ClickHouse 26.1+
  • Using ADD PROJECTION my_projection (SELECT _part_offset ORDER BY my, columns) if ClickHouse 25.6+
  • Raise error if ClickHouse <25.6
  • Black has formatted the modified files, modifying a few bits in unmodified functions.
  • Fixes feat: Allow INDEX syntax to add projections with _part_offset from 26.1 #650

Checklist

Delete items not relevant to your PR:


Note

Low Risk
Scoped to projection DDL generation in table materialization with backward-compatible query behavior and compile-time guards; main risk is wrong version-specific SQL on edge ClickHouse versions.

Overview
Adds an optional index field on each entry in the projections model config so you can declare lightweight index projections without writing raw ADD PROJECTION SQL. The add_index_and_projections macro still emits ADD PROJECTION … (query) when query is set; with index only, it builds version-specific DDL: INDEX … TYPE basic on ClickHouse 26.1+, or (SELECT _part_offset ORDER BY …) on 25.6–26.0. Compile-time errors block query + index, missing both, or index on servers before 25.6. The 1.10.1 changelog documents the feature; integration tests cover happy paths, validation messages, and version gating (existing projection tests were reformatted).

Reviewed by Cursor Bugbot for commit 06962eb. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 06962eb. Configure here.

res = run_dbt(["run", "--select", "no_query_or_index"], expect_pass=False)
assert any(
"must specify either 'query' or 'index'" in (r.message or "") for r in res.results
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing seed call creates implicit test ordering dependency

Medium Severity

test_raises_when_neither_query_nor_index omits the run_dbt(["seed"]) call that every other test in this file includes. The model references {{ source('raw', 'people') }}, and the materialization template executes CREATE TABLE ... EMPTY AS (SELECT ... FROM people) before calling add_index_and_projections where the expected validation error is raised. Without the seed table in the database, the model fails at table creation with a missing-table error instead of the projection validation error, causing the assertion checking for "must specify either 'query' or 'index'" to fail for the wrong reason.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 06962eb. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Allow INDEX syntax to add projections with _part_offset from 26.1

1 participant