zzwqqq commented on code in PR #5385:
URL: https://github.com/apache/calcite/pull/5385#discussion_r4504894047
##########
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##########
@@ -1595,10 +1686,80 @@ private RelNode findInputRel(CorRef corVar) {
return getCorRel(corVar);
}
+ /** Checks whether this input can be repeated or shared during decorrelation.
+ * Ordinary table scans assume stable contents within a query; unknown
+ * operators are not assumed deterministic.
+ */
+ private boolean isDeterministic(RelNode rel) {
+ rel = rel.stripped();
+ try {
+ // These operators have expressions outside accept(RexShuttle).
+ if (rel instanceof Aggregate) {
+ for (AggregateCall call : ((Aggregate) rel).getAggCallList()) {
+ if (!call.getAggregation().isDeterministic()) {
+ return false;
+ }
+ call.rexList.forEach(RelDecorrelator::checkDeterministicExpression);
+ }
+ } else if (rel instanceof Window) {
+ for (Window.Group group : ((Window) rel).groups) {
+
group.aggCalls.forEach(RelDecorrelator::checkDeterministicExpression);
+ checkDeterministicExpression(group.lowerBound.getOffset());
+ checkDeterministicExpression(group.upperBound.getOffset());
+ }
+ } else if (rel instanceof Match) {
+ final Match match = (Match) rel;
+ checkDeterministicExpression(match.getPattern());
+ checkDeterministicExpression(match.getAfter());
+ checkDeterministicExpression(match.getInterval());
+
match.getMeasures().values().forEach(RelDecorrelator::checkDeterministicExpression);
+ match.getPatternDefinitions().values()
+ .forEach(RelDecorrelator::checkDeterministicExpression);
+ } else if (rel instanceof AsofJoin) {
+ checkDeterministicExpression(((AsofJoin) rel).getMatchCondition());
+ } else if (rel instanceof ConditionalCorrelate) {
+ checkDeterministicExpression(((ConditionalCorrelate)
rel).getCondition());
+ } else if (!(rel instanceof Project
+ || rel instanceof Filter
+ || rel instanceof Calc
+ || rel instanceof Join
+ || rel instanceof Correlate
+ || rel instanceof Sort
+ || rel instanceof SetOp
+ || rel instanceof Exchange
+ || rel instanceof TableScan
+ || rel instanceof Values
+ || rel instanceof TableFunctionScan
+ || rel instanceof Snapshot
+ || rel instanceof Collect
+ || rel instanceof Uncollect)) {
+ return false;
Review Comment:
Thanks, changed as suggested.
--
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]