Vladislav Pyatkov created IGNITE-29322:
------------------------------------------
Summary: [Calcite] Recursive CTE fails in Inbox.rewindInternal
when a computed window sort key is trimmed
Key: IGNITE-29322
URL: https://issues.apache.org/jira/browse/IGNITE-29322
Project: Ignite
Issue Type: Bug
Components: sql
Reporter: Vladislav Pyatkov
Attachments: recursive-window-rewind-reproducer.patch
A recursive CTE joining its current delta to a static input containing
ROW_NUMBER()
can fail with UnsupportedOperationException in Inbox.rewindInternal. The failure
is reproduced when the window uses a computed sort key, k * CAST(? AS INTEGER),
and that key is not retained in the recursive projection.
Query example:
{code}
WITH RECURSIVE ranked AS (
SELECT id, parent_id,
ROW_NUMBER() OVER (ORDER BY k * CAST(? AS INTEGER), id) AS rn
FROM nodes
), tree(id, parent_id, rn, depth) AS (
SELECT id, parent_id, rn, 1
FROM ranked
WHERE id = 1
UNION ALL
SELECT r.id, r.parent_id, r.rn, t.depth + 1
FROM ranked r
JOIN tree t ON r.parent_id = t.id
)
SELECT id, rn, depth
FROM tree
ORDER BY id;
{code}
Actual exception:
{noformat}
Query execution fails. Relevant exception chain:
org.apache.ignite.internal.processors.query.IgniteSQLException:
An error occurred while query executing - null
Caused by: org.apache.ignite.IgniteException: null
Caused by: java.lang.UnsupportedOperationException
at
org.apache.ignite.internal.processors.query.calcite.exec.rel.Inbox.rewindInternal(Inbox.java:158)
at
org.apache.ignite.internal.processors.query.calcite.exec.rel.AbstractNode.rewind(AbstractNode.java:132)
at java.util.Collections$SingletonList.forEach(Collections.java:4967)
at
org.apache.ignite.internal.processors.query.calcite.exec.rel.AbstractNode.rewind(AbstractNode.java:135)
Plan observations
The failing recursive term contains this shape (details omitted):
IgniteRepeatUnion
... seed ...
IgniteProject
IgniteHashJoin
IgniteProject -- drops the computed window sort key
IgniteWindow -- ROW_NUMBER()
IgniteExchange(single)
IgniteSort
IgniteTableScan(NODES) -- projects k * ?0
IgniteProject
IgniteRecursiveTableScan
{noformat}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)