fix: Primary key declaration#648
Open
vrkirillov wants to merge 16 commits into
Open
Conversation
Renamed macros in table materialization: 1. order_cols to order_by_cause 2. partition_cols to partition_by_clause
…re unspecified Replace single quotes with double quotes in order_by_clause macro Remove parentheses from MergeTree in order_by_clause macro
…able materialization
vrkirillov
commented
May 27, 2026
vrkirillov
left a comment
Contributor
Author
There was a problem hiding this comment.
fix recommendations in Cursor
For MergeTree tables, prefer this order: ENGINE = MergeTree() ORDER BY (...) PARTITION BY (...) PRIMARY KEY (...) TTL ... SETTINGS ...
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit fb97021. Configure here.
…that the helper renders geRename make_columns to expression_list_clause to better reflect that the helper renders generic ClickHouse expression lists, not only column names. Simplify order_by_clause by handling the three cases directly: - use explicit order_by when configured - fall back to primary_key when order_by is omitt_by is omitt_by is omitt_by is omitt_by is omitt_by is omitt_by is omitt_by is o - otherwise use tuple()
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
Checklist
Delete items not relevant to your PR:
Note
Medium Risk
Changes default DDL for MergeTree tables without
order_by(PK-only vsORDER BY (tuple())), which can affect physical layout and query performance for existing models.Overview
Adds MergeTree
primary_keymodel config (string or column list) so DDL can emitPRIMARY KEY (...)fortable,distributed_table, and seed materializations, with docs and YAML/SQL examples in the changelog.Refactors shared DDL helpers in
table.sql:make_columns, renamedorder_by_clause/partition_by_clause, andprimary_keybeforeorder by/partition by. When onlyprimary_keyis set (noorder_by), the adapter no longer forces defaultORDER BY (tuple()), matching ClickHouse’s ability to rely on the primary key for sorting.Integration tests assert
system.tablesprimary_keyandsorting_keyfor models with PK-only vs PK + explicitorder_by.Reviewed by Cursor Bugbot for commit c8c860d. Bugbot is set up for automated code reviews on this repo. Configure here.