lsyldliu commented on code in PR #21601:
URL: https://github.com/apache/flink/pull/21601#discussion_r1070898438
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -1062,6 +1062,63 @@ public void testSumAggWithGroupKey() throws Exception {
tableEnv.executeSql("drop table test_sum_group");
}
+ @Test
+ public void testAvgAggFunctionPlan() {
+ // test explain
+ String actualPlan = explainSql("select x, avg(y) from foo group by x");
+
assertThat(actualPlan).isEqualTo(readFromResource("/explain/testAvgAggFunctionPlan.out"));
+ }
+
+ @Test
+ public void testAvgAggFunction() throws Exception {
+ tableEnv.executeSql(
+ "create table test_avg(a int, x string, y string, z int, f
bigint, d decimal(20, 5), e double)");
+ tableEnv.executeSql(
+ "insert into test_avg values (1, NULL, '2', 1, 2,
2.22, 2.3), "
+ + "(1, NULL, 'b', 2, NULL, 3.33, 3.4), "
+ + "(2, NULL, '4', 1, 2, 4.55, 4.5), "
+ + "(2, NULL, NULL, 4, 3, 5.66, 5.2)")
+ .await();
+
+ // test avg all element is null
+ List<Row> result =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select avg(x) from
test_avg").collect());
+ assertThat(result.toString()).isEqualTo("[+I[null]]");
+
+ // test avg that some string elements can't convert to double
+ List<Row> result2 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select avg(y) from
test_avg").collect());
+ assertThat(result2.toString()).isEqualTo("[+I[3.0]]");
Review Comment:
As the following explains, it should be `[+I[3.0]]`, the null element
doesn't count.
--
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]