GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: support ClickHouse ORDER BY WITH FILL and INTERPOLATE (#2467) by fudianchn · Pull Request #2469 · JSQLParser/JSqlParser

Conversation

@fudianchn

@fudianchn fudianchn commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What

Support ClickHouse's ORDER BY ... WITH FILL modifier and the query-level INTERPOLATE clause, following the ClickHouse grammar: per element [WITH FILL] [FROM expr] [TO expr] [STEP expr] [STALENESS expr] (the step may be an INTERVAL literal), and after the ORDER BY list an optional INTERPOLATE [(col [AS expr], ...)] where the bare form fills all allowed columns.

Why

SELECT d, v FROM t ORDER BY d WITH FILL FROM toDate('2024-01-01') TO toDate('2024-02-01') STEP INTERVAL 1 DAY INTERPOLATE (v AS v + 1) currently fails with a ParseException on WITH. WITH FILL is the standard ClickHouse construct for gap filling in time series, so statements using it cannot be parsed at all.

How

  • OrderByElement carries a new WithFill holder (its presence marks the element as filled; from/to/step/staleness are optional expressions). This mirrors ClickHouse, where the bounds belong to the order by element.
  • Select (shared by PlainSelect, ParenthesedSelect and SetOperationList) carries the List<InterpolateElement> as a sibling of orderByElements, mirroring ClickHouse, where INTERPOLATE is a query-level attribute. The existing union hoisting for orderByElements is extended so SELECT ... UNION SELECT ... ORDER BY x WITH FILL INTERPOLATE (...) lands on the SetOperationList.
  • Rendering in both toString() and the deparser (bounds rendered through the expression visitor), and OrderByValidator/SelectValidator walk the new expressions.
  • FILL, STEP, STALENESS and INTERPOLATE are declared as non-reserved keywords (inside the NonReservedWord range), so they remain usable as plain column names (SELECT fill, step FROM t ORDER BY interpolate still parses).

Root cause

The grammar had no production for the WITH FILL modifier family and no INTERPOLATE clause; the element-level bounds and the query-level column list are modeled after the ClickHouse reference parser (bounds only parsed after WITH FILL, in fixed FROM/TO/STEP/STALENESS order).

Testing

  • ClickHouseTest: 9 new tests covering the issue statement, bare WITH FILL, FROM/TO/STEP, STEP INTERVAL plus STALENESS, DESC/NULLS LAST combinations, INTERPOLATE variants (multiple items, item without AS, bare INTERPOLATE), a UNION with hoisting, a subquery, and column names using the new keywords.
  • ./gradlew test: 4793 tests, 0 failures (26 skipped, pre-existing).

Performance

gradle jmh, JSQLParserBenchmark.parseSQLStatements on performance.sql, version=latest, 10 forks × 10 iterations (100 samples) on a 32-core host:

build ms/op
master 3.689 ± 0.019
branch 3.690 ± 0.020

The difference is within the confidence intervals: no regression.

Notes

  • compileJavacc emits one additional choice-conflict warning (12 → 13) caused by the INTERPOLATE optional in PlainSelect's clause tail; the token has exactly one valid parse at that position, and the repo already carries such warnings (tracked in compileJavacc emits JavaCC warnings for shadowed literals and unreachable DATA_TYPE branches #2403).
  • INTERPOLATE () with an empty list is accepted and normalized to the bare INTERPOLATE form (both fill all allowed columns in ClickHouse).

Fixes #2467

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fudianchn
fix: support ClickHouse ORDER BY WITH FILL and INTERPOLATE (JSQLParse…
74c9a4c
…r#2467)

Parse the ClickHouse WITH FILL modifier on ORDER BY elements together
with the query-level INTERPOLATE clause, matching the upstream grammar:
per element [WITH FILL] [FROM e] [TO e] [STEP e] [STALENESS e] (the step
may be an INTERVAL literal), and after the ORDER BY list an optional
INTERPOLATE [(col [AS expr], ...)] where the bare form fills all allowed
columns.

OrderByElement carries a new WithFill holder and Select (shared by
PlainSelect and SetOperationList, with union hoisting) carries the
interpolate column list. Rendering goes through both toString and the
deparser, and the validators walk the new expressions. The keywords
FILL, STEP, STALENESS and INTERPOLATE are declared non-reserved, so they
remain usable as plain column names.

Signed-off-by: 付典 <[email protected]>
@fudianchn fudianchn mentioned this pull request Aug 15, 2026
[BUG] JSQLParser 5.4-SNAPSHOT : ClickHouse : ORDER BY ... WITH FILL / INTERPOLATE not supported #2467
Closed
@manticore-projects

manticore-projects commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Thank you much!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manticore-projects
manticore-projects merged commit 406a4d4 into JSQLParser:master Aug 15, 2026
7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@fudianchn
fudianchn deleted the fix/clickhouse-order-by-with-fill-2467 branch August 21, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] JSQLParser 5.4-SNAPSHOT : ClickHouse : ORDER BY ... WITH FILL / INTERPOLATE not supported

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@fudianchn @manticore-projects
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.