xuzifu666 commented on code in PR #5003:
URL: https://github.com/apache/calcite/pull/5003#discussion_r3377383637


##########
core/src/main/java/org/apache/calcite/sql/fun/SqlAvgAggFunction.java:
##########
@@ -86,4 +96,19 @@ public enum Subtype {
     VAR_POP,
     VAR_SAMP
   }
+
+  @Override public @Nullable RexNode getConstantResult(RexBuilder rexBuilder,
+      RelDataType returnType) {
+    // Only statistical functions (variance and standard deviation) return 0 
for constant values.
+    // AVG and other functions should not be optimized through this interface.

Review Comment:
   Thanks for point out this issue, this requires proper ```NULL``` semantics 
handling. When ```GROUP BY``` key/expression is ```NULL```, we generate: 
```CASE WHEN ... IS NULL THEN NULL ELSE 0 END``` to preserve correct ```NULL``` 
semantics.



-- 
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]

Reply via email to