Skip to content

feat(ast,parser): round-trip ClickHouse SAMPLE and ORDER BY WITH FILL - #534

Open
basili4-1982 wants to merge 1 commit into
ajitpratap0:mainfrom
basili4-1982:feat/clickhouse-sample-withfill
Open

feat(ast,parser): round-trip ClickHouse SAMPLE and ORDER BY WITH FILL#534
basili4-1982 wants to merge 1 commit into
ajitpratap0:mainfrom
basili4-1982:feat/clickhouse-sample-withfill

Conversation

@basili4-1982

Copy link
Copy Markdown

Summary

ClickHouse SAMPLE and ORDER BY … WITH FILL are parsed but dropped on render
(they do not round-trip), silently losing query semantics. This PR models both and
makes them round-trip.

Root cause

  • SampleClause existed on SelectStatement but had no SQL() render → SAMPLE lost.
  • ORDER BY … WITH FILL FROM x TO y STEP z was skipped by the parser
    (skipClickHouseWithFillTail) and not stored.

Changes

  • pkg/sql/ast/ast_clauses.go: new WithFillClause (From/To/Step); added
    OrderByExpression.WithFill *WithFillClause.
  • pkg/sql/parser/select_clauses.go: ClickHouse WITH FILL tail is now parsed into
    WithFillClause instead of being skipped.
  • pkg/sql/ast/sql.go:
    • SampleClause.SQL() renders SAMPLE N[/D] [OFFSET M[/K]];
    • SelectStatement.SQL() emits SAMPLE after ARRAY JOIN/before PREWHERE;
    • orderBySQL() / withFillSQL() render WITH FILL [FROM x] [TO y] [STEP z].
  • pkg/sql/parser/clickhouse_sample_withfill_test.go: regression round-trip tests.

Test plan

  • New TestClickHouseSampleAndWithFillRoundtrip (sample ratio/fraction/offset,
    with-fill step/full/desc) — all green
  • go test -short ./pkg/sql/ast/ ./pkg/sql/parser/ ./pkg/gosqlx/ ./pkg/formatter/ green

- SampleClause: renders SAMPLE [N/D] [OFFSET M/K] after FROM/ARRAY JOIN.
- WithFillClause (From/To/Step) modeled on OrderByExpression; parser captures
  it instead of skipping; orderBySQL renders WITH FILL ... back.
- Regression tests for SAMPLE (ratio/frac/offset) and WITH FILL (step/full/desc).
@vercel

vercel Bot commented Aug 21, 2026

Copy link
Copy Markdown

@basili4-1982 is attempting to deploy a commit to the coolajitpratapsingh0-9932's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added parser ast AST node changes labels Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ast AST node changes parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant