godfreyhe commented on code in PR #21608:
URL: https://github.com/apache/flink/pull/21608#discussion_r1070833142
##########
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 testMinAggFunctionPlan() {
Review Comment:
it's better the plan test should not be in ITCase
##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveMinAggFunction.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.functions.hive;
+
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.expressions.UnresolvedReferenceExpression;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+
+import static
org.apache.flink.table.expressions.ApiExpressionUtils.unresolvedRef;
+import static
org.apache.flink.table.planner.expressions.ExpressionBuilder.ifThenElse;
+import static
org.apache.flink.table.planner.expressions.ExpressionBuilder.isNull;
+import static
org.apache.flink.table.planner.expressions.ExpressionBuilder.lessThan;
+import static
org.apache.flink.table.planner.expressions.ExpressionBuilder.nullOf;
+
+/** built-in hive min aggregate function. */
+public class HiveMinAggFunction extends HiveDeclarativeAggregateFunction {
+
+ private final UnresolvedReferenceExpression min = unresolvedRef("min");
+ private DataType resultType;
+
+ @Override
+ public int operandCount() {
+ return 1;
+ }
+
+ @Override
+ public UnresolvedReferenceExpression[] aggBufferAttributes() {
+ return new UnresolvedReferenceExpression[] {min};
+ }
+
+ @Override
+ public DataType[] getAggBufferTypes() {
+ return new DataType[] {getResultType()};
+ }
+
+ @Override
+ public DataType getResultType() {
+ return resultType;
+ }
+
+ @Override
+ public Expression[] initialValuesExpressions() {
+ return new Expression[] {
+ /* min */
+ nullOf(getResultType())
+ };
+ }
+
+ @Override
+ public Expression[] accumulateExpressions() {
+ return new Expression[] {
+ /* min = */ ifThenElse(
+ isNull(operand(0)),
+ min,
+ ifThenElse(
+ isNull(min),
+ operand(0),
+ ifThenElse(lessThan(operand(0), min), operand(0),
min)))
+ };
+ }
+
+ @Override
+ public Expression[] retractExpressions() {
+ throw new TableException("Min aggregate function does not support
retraction.");
+ }
+
+ @Override
+ public Expression[] mergeExpressions() {
+ return new Expression[] {
+ /* max = */ ifThenElse(
Review Comment:
min
##########
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 testMinAggFunctionPlan() {
+ // test explain
+ String actualPlan = explainSql("select x, min(y) from foo group by x");
+
assertThat(actualPlan).isEqualTo(readFromResource("/explain/testMinAggFunctionPlan.out"));
+ }
+
+ @Test
+ public void testMinAggFunction() throws Exception {
Review Comment:
all type should be cover, including unsupported types
--
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]