Skip to content

[CALCITE-7814] Support the SQL-standard CYCLE clause in recursive CTEs - #5294

Open
vldpyatkov wants to merge 7 commits into
apache:mainfrom
vldpyatkov:calcite-7814
Open

vldpyatkov wants to merge 7 commits into
apache:mainfrom
vldpyatkov:calcite-7814

Conversation

@vldpyatkov

@vldpyatkov vldpyatkov commented Sep 25, 2026 •

Copy link
Copy Markdown

CALCITE-7814
The implemented CYCLE syntax

cycle_clause ::= CYCLE key_column { ',' key_column }
                 SET mark_column
                 [ TO cycle_value DEFAULT non_cycle_value ]
                 USING path_column

Explicit mark values must be distinct, non-null Boolean literals or compatible single-character string literals. Omitting TO ... DEFAULT ... uses TRUE and FALSE, respectively.
The clause is represented by SqlCycleClause on SqlWithItem. During validation, CycleRewriter rewrites the query to maintain the cycle mark and an ARRAY<ROW<...>> path. A row that closes a cycle is returned but is not expanded further.

During implementation, I found an issue with comparing ARRAY<ROW<...>> values and fixed the comparer to compare their elements by content. This is needed for correct duplicate elimination when the result includes a cycle path column.

@vldpyatkov vldpyatkov changed the title CALCITE-7814 Support the SQL-standard CYCLE clause in recursive CTEs [CALCITE-7814] Support the SQL-standard CYCLE clause in recursive CTEs Sep 25, 2026
@sonarqubecloud

Copy link
Copy Markdown

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