Skip to content

feat(sql): wire an actual SQL dialect selector, enable ClickHouse parsing - #147

Merged
zzylol merged 2 commits into
mainfrom
feat/clickhouse-sql-dialect
Jul 22, 2026
Merged

zzylol merged 2 commits into
mainfrom
feat/clickhouse-sql-dialect

Conversation

@milindsrivastava1997

@milindsrivastava1997 milindsrivastava1997 commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

This PR turns on ClickHouse SQL parsing in the SQL front end, which today silently ignores the requested dialect and always parses with DataFusion's generic SQL grammar. It's prep for testing real ClickHouse-flavored query corpora (like the BGP analytics one in #148) against the lowering pipeline.

Summary

  • SqlDialect::ClickhouseSQL existed on QueryLanguage::SQL(_) but lower_sql_batch unconditionally rejected it with UnsupportedDialect, and lower_sql never consulted the dialect at all -- DataFusion's default GenericDialect was always used regardless.
  • sqlparser (already a transitive dependency via DataFusion) vendors a ClickHouseDialect that parses ClickHouse's array-lambda syntax (arrayFilter(x -> ..., ...)) and arr[-1] indexing, neither of which GenericDialect accepts. No new dependency.
  • Adds SqlLowerer::with_dialect / lower_sql_dialect, threads the dialect into DataFusion's SessionConfig (datafusion.sql_parser.dialect), and auto-registers a schema for dotted catalog table names (e.g. bgp.bgp_updates) since DataFusion requires the parent schema to exist before a qualified table can be registered into it.
  • lower_sql_batch now only rejects ElasticSQL, which has no vendored parser at all.
  • lower_sql keeps its existing signature/behavior (delegates to lower_sql_dialect with SqlDialect::DataFusionSQL) -- no breaking change for existing callers/tests.
  • Includes an unrelated one-file cargo fmt drift fix (cost_model.rs), split into its own commit, needed to get the workspace-wide fmt pre-commit hook green.

Scope note

This is parsing-only. ClickHouse-specific builtin functions (uniqExact, countIf, toStartOfInterval, lagInFrame, isIPAddressInRange, multiIf, arrayJoin, groupUniqArray, ...) are still unknown to DataFusion's planner and still fail to plan. Registering UDF equivalents for those is separate follow-up work, not attempted here.

Stack

Base for #148, which exercises this dialect switch against a real-world ClickHouse query corpus.

Test plan

  • cargo build --workspace
  • cargo test -p asap-frontend-sql (existing suite green, 65 tests)
  • cargo clippy -p asap-frontend-sql --all-targets -- clean

🤖 Generated with Claude Code

Unrelated formatting drift caught by the workspace-wide cargo-fmt
pre-commit hook while preparing an unrelated change. No behavior change.
…sing

`SqlDialect::ClickhouseSQL` existed on `QueryLanguage::SQL` but `lower_sql_batch`
unconditionally rejected it with `UnsupportedDialect`, and `lower_sql` never
consulted the dialect at all -- DataFusion's default GenericDialect was always
used. sqlparser (already a transitive dep via DataFusion) vendors a
`ClickHouseDialect` that parses ClickHouse's array-lambda syntax
(`arrayFilter(x -> ..., ...)`) and `arr[-1]` indexing, neither of which
GenericDialect accepts.

Adds `SqlLowerer::with_dialect` / `lower_sql_dialect`, threads the dialect into
DataFusion's `SessionConfig` (`datafusion.sql_parser.dialect`), and
auto-registers a schema for dotted catalog table names (e.g. `bgp.bgp_updates`)
since DataFusion requires the parent schema to exist before a qualified table
can be registered into it. `lower_sql_batch` now only rejects `ElasticSQL`,
which has no vendored parser.

This is parsing-only: ClickHouse-specific builtin functions (`uniqExact`,
`countIf`, `toStartOfInterval`, ...) are still unknown to DataFusion's planner
and still fail to plan -- registering UDF equivalents is separate follow-up
work, not attempted here.
@zzylol
zzylol merged commit 707a062 into main Jul 22, 2026
3 checks passed
@zzylol
zzylol deleted the feat/clickhouse-sql-dialect branch July 22, 2026 02:28
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.

2 participants