feat(compiler): add DDL AST and ClickHouse DDL codegen

What does this MR do and why?

In preparation for !867 (merged), !857 (merged), this MR splits ast.rs into ast/dml.rs (existing query AST, unchanged) and ast/ddl.rs (new DDL types), so that DDL statements can be programmatically composed for Clickhouse, demonstrated in !867 (merged).

Generally, this MR enables ontology-driven DDL generation for schema migrations. The migration orchestrator can build CreateTable structs from ontology metadata and call emit_create_table with a version prefix, instead of parsing raw graph.sql at runtime. Follow-up MR will extend ontology YAML with ClickHouse DDL hints.

This MR has already been tested E2E in !867 (merged).


Overview of DDL AST types

Database-agnostic where possible:

  • CreateTable — name, columns, indexes, projections, engine, order_by, primary_key, settings
  • ColumnDef — name, type, default, codec
  • ColumnType — Int64, UInt64, Bool, String, Date32, Timestamp, Nullable, LowCardinality
  • Codec — ZSTD, Delta, LZ4
  • IndexDef / IndexType — MinMax, Set, BloomFilter
  • ProjectionDef — Reorder (SELECT * ORDER BY) and Aggregate (SELECT ... GROUP BY)
  • Engine — name + args (e.g. ReplacingMergeTree(_version, _deleted))
  • TableSetting — key/value pairs

ClickHouse DDL codegen

ClickHouse-specific SQL spelling lives in the codegen layer, not the AST. The emit_create_table(&CreateTable) -> String produces the full DDL statement including CODECs, PROJECTIONs, INDEXes, ENGINE, ORDER BY, PRIMARY KEY, and SETTINGS.

Edited by Michael Usachenko

Merge request reports

Loading