lsyldliu commented on code in PR #21605:
URL: https://github.com/apache/flink/pull/21605#discussion_r1073075357
##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -1062,6 +1062,87 @@ public void testSumAggWithGroupKey() throws Exception {
tableEnv.executeSql("drop table test_sum_group");
}
+ @Test
+ public void testMaxAggFunctionPlan() {
+ // test explain
+ String actualPlan = explainSql("select x, max(y) from foo group by x");
+
assertThat(actualPlan).isEqualTo(readFromResource("/explain/testMaxAggFunctionPlan.out"));
+ }
+
+ @Test
+ public void testMaxAggFunction() throws Exception {
+ tableEnv.executeSql(
+ "create table test_max(a int, b boolean, x string, y string, z
int, d decimal(10,5), e float, f double, ts timestamp, dt date, bar binary)");
+ tableEnv.executeSql(
+ "insert into test_max values (1, true, NULL, '2', 1,
1.11, 1.2, 1.3, '2021-08-04 16:26:33.4','2021-08-04', 'data1'), "
+ + "(1, false, NULL, 'b', 2, 2.22, 2.3, 2.4,
'2021-08-06 16:26:33.4','2021-08-07', 'data2'), "
+ + "(2, false, NULL, '4', 1, 3.33, 3.5, 3.6,
'2021-08-08 16:26:33.4','2021-08-08', 'data3'), "
+ + "(2, true, NULL, NULL, 4, 4.45, 4.7, 4.8,
'2021-08-10 16:26:33.4','2021-08-01', 'data4')")
+ .await();
+
+ // test max with all elements are null
+ List<Row> result =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(x) from
test_max").collect());
+ assertThat(result.toString()).isEqualTo("[+I[null]]");
+
+ // test max with some elements are null
+ List<Row> result2 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(y) from
test_max").collect());
+ assertThat(result2.toString()).isEqualTo("[+I[b]]");
+
+ // test max with some elements repeated
+ List<Row> result3 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(z) from
test_max").collect());
+ assertThat(result3.toString()).isEqualTo("[+I[4]]");
+
+ // test max with decimal type
+ List<Row> result4 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(d) from
test_max").collect());
+ assertThat(result4.toString()).isEqualTo("[+I[4.45000]]");
+
+ // test max with float type
+ List<Row> result5 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(e) from
test_max").collect());
+ assertThat(result5.toString()).isEqualTo("[+I[4.7]]");
+
+ // test max with double type
+ List<Row> result6 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(f) from
test_max").collect());
+ assertThat(result6.toString()).isEqualTo("[+I[4.8]]");
+
+ // test max with boolean type
+ List<Row> result7 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(b) from
test_max").collect());
+ assertThat(result7.toString()).isEqualTo("[+I[true]]");
+
+ // test max with timestamp type
+ List<Row> result8 =
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select max(ts) from
test_max").collect());
+
assertThat(result8.toString()).isEqualTo("[+I[2021-08-10T16:26:33.400]]");
Review Comment:
I've run it use Hive3, the test passed.
--
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]