wuchong commented on a change in pull request #9331: 
[FLINK-13523][table-planner-blink] Verify and correct arithmetic function's 
semantic for Blink planner
URL: https://github.com/apache/flink/pull/9331#discussion_r311886806
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/rules/logical/SplitAggregateRule.scala
 ##########
 @@ -304,19 +302,22 @@ class SplitAggregateRule extends RelOptRule(
             aggGroupCount + index + avgAggCount + 1,
             finalAggregate.getRowType)
           avgAggCount += 1
-          // TODO
+          // Make a guarantee that the final aggregation returns NULL if 
underlying count is ZERO.
+          // We use SUM0 for underlying sum, which may run into ZERO / ZERO,
+          // and division by zero exception occurs.
+          // @see Glossary#SQL2011 SQL:2011 Part 2 Section 6.27
           val equals = relBuilder.call(
             FlinkSqlOperatorTable.EQUALS,
             countInputRef,
             relBuilder.getRexBuilder.makeBigintLiteral(JBigDecimal.valueOf(0)))
-          val falseT = relBuilder.call(FlinkSqlOperatorTable.DIVIDE, 
sumInputRef, countInputRef)
-          val trueT = relBuilder.cast(
+          val ifTrue = relBuilder.cast(
             relBuilder.getRexBuilder.constantNull(), 
aggCall.`type`.getSqlTypeName)
+          val ifFalse = relBuilder.call(FlinkSqlOperatorTable.DIVIDE, 
sumInputRef, countInputRef)
 
 Review comment:
   Thanks.  Please rebase master and resolve the conflicts. Others looks good 
to me now.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to