iwanttobepowerful opened a new pull request, #5359: URL: https://github.com/apache/calcite/pull/5359
CALCITE-7887 # Root cause SubQueryRemoveRule.matchProject locates the sub-query to rewrite with RexUtil.SubQueryFinder, which is a deep RexVisitorImpl and therefore descends into a RexOver's operands, partition keys and order keys. It then calls LogicVisitor.find to compute the Logic under which that sub-query is evaluated. However, LogicVisitor.visitOver only called end(over, arg) and never visited the operands or the window of the RexOver. As a result, a sub-query nested anywhere inside a window function was found by SubQueryFinder but was invisible to LogicVisitor, so the collected logic set was empty and LogicVisitor.find threw IllegalArgumentException: not found. # Fix LogicVisitor.visitOver now visits the aggregate operands, the partition keys, the order keys and the bounds of the window. They are visited with Logic.TRUE_FALSE_UNKNOWN, because a window function consumes the value of these expressions, not just whether they are true. For example, COUNT(x) ignores NULLs, so UNKNOWN must be distinguished from FALSE; PARTITION BY / ORDER BY treat NULL and FALSE as different keys. Using a weaker logic such as UNKNOWN_AS_FALSE could therefore produce wrong results. Only Project is affected, since window functions can only appear in the SELECT list (QUALIFY is converted to a Filter on top of a Project). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
