You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Vladislav Pyatkov (Jira)" <ji...@apache.org> on 2026/09/23 21:13:00 UTC

[jira] [Created] (CALCITE-7814) Support the SQL-standard CYCLE clause in recursive CTEs

Vladislav Pyatkov created CALCITE-7814:
------------------------------------------

             Summary: Support the SQL-standard CYCLE clause in recursive CTEs
                 Key: CALCITE-7814
                 URL: https://issues.apache.org/jira/browse/CALCITE-7814
             Project: Calcite
          Issue Type: New Feature
          Components: core
            Reporter: Vladislav Pyatkov


Add support for the SQL-standard _CYCLE_ clause in recursive common table expressions, including parsing, validation, relational conversion, and execution.
_CYCLE_ detects repeated keys within each recursive path and adds cycle-mark and path columns. A cycle-closing row is returned with its mark set, but does not produce further recursive expansion.
Example:
{code:sql}
WITH RECURSIVE
  edges(src, dst) AS (
    VALUES ('A', 'B'), ('B', 'C'), ('C', 'A')
  ),
  walk(node) AS (
    VALUES ('A')
    UNION ALL
    SELECT e.dst
    FROM walk w JOIN edges e ON e.src = w.node
  )
  CYCLE node SET is_cycle TO 'Y' DEFAULT 'N'
    USING cycle_path
SELECT node, is_cycle, cycle_path
FROM walk;
{code}
The traversal follows A → B → C → A. The final A is marked as a cycle-closing row, and recursion stops along that path.

Include execution tests for single and composite cycle keys, negative validation tests with clear error messages, and a documented example.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)