Skip to content

Expose structured ORDER BY fragment parsing - #2620

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/order-by-fragment-parser
Open

Expose structured ORDER BY fragment parsing#2620
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/order-by-fragment-parser

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

Consumers that assemble queries from independent sort specifications currently need to wrap fragments in a SELECT or retain them as opaque expressions. For example, DBeaver's ORDER BY handling uses CustomExpression for a sort fragment (pinned consumer code). A fragment API exposes the expression and sort flags directly, so callers can inspect and rewrite them through the ordinary AST.

Add CCJSqlParserUtil.parseOrderByElements(String) and its parser-configuration overload. Input such as COALESCE(score, 0) DESC NULLS LAST, id ASC produces a List<OrderByElement>; the input excludes the ORDER BY keywords. Null or empty input returns an empty list, and trailing tokens are rejected.

The existing ORDER BY clause now delegates to a shared element-list production. Column-type parsing and the new API also share fragment parser setup, fast/complex retry, full-input checking, and exception handling. Existing column-type behavior is preserved, and each invocation starts with fresh parser state.

Validation: full Java 17 Gradle check passes, including the zero-conflict JavaCC grammar gate, tests, formatting, Checkstyle, PMD, and SpotBugs. Tests compare fragments with complete ORDER BY clauses, exercise configured quoting and parameter indices, verify custom expression deparsing and round trips, and reject incomplete or trailing SQL.

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