darpan-e6 commented on code in PR #4970:
URL: https://github.com/apache/calcite/pull/4970#discussion_r3315311244
##########
core/src/main/java/org/apache/calcite/plan/RelOptUtil.java:
##########
@@ -3346,6 +3346,21 @@ public static List<RexNode> pushPastProject(List<?
extends RexNode> nodes,
// function? Possibly. But it's invalid SQL, so don't go there.
return null;
}
+ // [CALCITE-7551] Refuse to merge if it would duplicate a
+ // non-deterministic expression (e.g. RAND()).
+ final List<RexNode> bottom = project.getProjects();
+ final int[] refs = new int[bottom.size()];
+ new RexVisitorImpl<Void>(true) {
+ @Override public Void visitInputRef(RexInputRef ref) {
+ refs[ref.getIndex()]++;
+ return null;
+ }
+ }.visitEach(nodes);
+ for (int i = 0; i < refs.length; i++) {
Review Comment:
As far as I understand, CURRENT_TIMESTAMP is actually different than
non-deterministic functions like RAND().
1. Non-deterministic function: it may return different values for every
evaluations.
1.1 Returns false to `isDeterministic()`.
1.2 Returns false to `isDynamicFunction()`.
2. Dynamic Function: It will return same value at every call site within one
statement; can differ across executions
2.1 Returns true to `isDeterministic()`.
2.2 Returns true to `isDynamicFunction()`.
And this path only blocks when we get `isDeterministic()` method response as
false. Dynamic functions like `CURRENT_TIMESTAMP` can be duplicated and
actually it is safe to duplicate them.
--
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]