luoyuxia commented on code in PR #21601:
URL: https://github.com/apache/flink/pull/21601#discussion_r1070986478


##########
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]]");
+
+        // test avg bigint with null element
+        List<Row> result3 =
+                CollectionUtil.iteratorToList(
+                        tableEnv.executeSql("select avg(f) from 
test_avg").collect());
+        assertThat(result3.toString()).isEqualTo("[+I[2.3333333333333335]]");
+
+        // test avg decimal
+        List<Row> result4 =
+                CollectionUtil.iteratorToList(
+                        tableEnv.executeSql("select avg(d) from 
test_avg").collect());
+        assertThat(result4.toString()).isEqualTo("[+I[3.940000000]]");

Review Comment:
   Agree. It should be `3.940000000`. Seems there's some issue in my EMR Hive.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to