Skip to content

WIP: Add support for all ClickHouse builtin functions, QUALIFY and WITH FILL FROM/TO/STEP#2357

Open
nastynaz wants to merge 15 commits intoquarylabs:mainfrom
nastynaz:naz/improve-clickhouse-dialect
Open

WIP: Add support for all ClickHouse builtin functions, QUALIFY and WITH FILL FROM/TO/STEP#2357
nastynaz wants to merge 15 commits intoquarylabs:mainfrom
nastynaz:naz/improve-clickhouse-dialect

Conversation

@nastynaz
Copy link
Copy Markdown

I'm a big user of sqlfluff and got tired with the lack of ClickHouse support so I decided to implement the missing parts that are most valuable to me.

This PR introduces:

Support for CilckHouse QUALIFY

Filters window queries and runs after HAVING

Support for ClickHouse WITH FILL FROM / WITH FILL TO / STEP

Used for filling in timeseries data.

Support for all builtin ClickHouse functions (WIP. Progress: 500/1618 added)

These are all the functions from the system.functions table along with their aliases and variants.

select * from system.functions -- 1618 in total

Some of these are case sensitive whilst others are case in-sensitive. For the case sensitive variants I've made sure that capitalisation policies won't automatically 'fix' them to incorrect values. Case insensitive functions still adhere to the capitalisation policy.

Summary

I'm making this a WIP PR whilst I finish the rest of the functions so that I can get feedback and make sure everything adheres to the coding standards here. Once this PR is merged sqruff will support much more of the ClickHouse dialect that sqlfluff.

It takes me a long time to check all of the aliases and variants to make sure I haven't missed any, so this might take a couple of weeks until it's done. Any feedback during this time would be much appreciated.

I also have helper Python scripts that can generate support for functions that are added in the future. I've left them out of this PR but if you think it's helpful I can add them.

Extend ClickHouse WITH FILL grammar so STEP accepts a full expression rather than only numeric or INTERVAL literals.

Add sqruff dialect fixtures for WITH FILL TO ... STEP ..., WITH FILL FROM ... STEP ..., and WITH FILL FROM ... TO ... STEP ... to prevent regressions.

Regenerate the existing sqlfluff order_by_with_fill AST fixture to reflect STEP values now being parsed as expression nodes.
Add a ClickHouse-specific CP03 path that fixes mapped built-in functions to canonical case and avoids unsafe rewrites for unknown functions.

Introduce a canonical function casing map (seeded with toInterval* functions) and add CP03 fixture coverage for default/lower/upper policies plus mixed known/unknown function calls.
Complete the first ClickHouse function batch (seq_id 1..50) with parser and CP03 test coverage.

- add batch parser fixture covering every function row in batch-0001
- extend ClickHouse CP03 canonical function casing map and fixture cases
- fix ClickHouse tuple-of-interval function argument parsing in dialect grammar
- refresh impacted ClickHouse dialect snapshots

Validation:
- cargo test --package sqruff-lib --test rules -- CP03.yml
- cargo test --package sqruff-lib-dialects --test dialects -- clickhouse
- clickhouse-client EXPLAIN SYNTAX on tuple interval examples
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 11, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing nastynaz:naz/improve-clickhouse-dialect (d0c4c40) with main (8e23ef1)2

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (b387429) during the generation of this report, so 8e23ef1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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.

1 participant