Repository: hive Updated Branches: refs/heads/master 5bbd86433 -> 1eef7e54d
HIVE-18254 : Use proper AVG Calcite primitive instead of Other_FUNCTION (Slim Bougerra via Ashutosh Chauhan) Signed-off-by: Ashutosh Chauhan <hashut...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/1eef7e54 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/1eef7e54 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/1eef7e54 Branch: refs/heads/master Commit: 1eef7e54daf0a8433ebcf25842d510ad7a2dd091 Parents: 5bbd864 Author: Slim Bouguerra <slim.bougue...@gmail.com> Authored: Sat Dec 9 23:11:32 2017 -0800 Committer: Ashutosh Chauhan <hashut...@apache.org> Committed: Sat Dec 9 23:11:32 2017 -0800 ---------------------------------------------------------------------- .../functions/HiveSqlAverageAggFunction.java | 53 ++++++++++++++++++++ .../translator/SqlFunctionConverter.java | 7 +++ 2 files changed, 60 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/1eef7e54/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/functions/HiveSqlAverageAggFunction.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/functions/HiveSqlAverageAggFunction.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/functions/HiveSqlAverageAggFunction.java new file mode 100644 index 0000000..b6563d9 --- /dev/null +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/functions/HiveSqlAverageAggFunction.java @@ -0,0 +1,53 @@ +/* + * 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.hadoop.hive.ql.optimizer.calcite.functions; + +import org.apache.calcite.sql.SqlAggFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlSplittableAggFunction; +import org.apache.calcite.sql.type.SqlOperandTypeChecker; +import org.apache.calcite.sql.type.SqlOperandTypeInference; +import org.apache.calcite.sql.type.SqlReturnTypeInference; + +public class HiveSqlAverageAggFunction extends SqlAggFunction { + public HiveSqlAverageAggFunction(SqlReturnTypeInference returnTypeInference, + SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker + ) + { + super( + "avg", + null, + SqlKind.AVG, + returnTypeInference, + operandTypeInference, + operandTypeChecker, + SqlFunctionCategory.NUMERIC, + false, + false); + } + + @Override + public <T> T unwrap(Class<T> clazz) { + if (clazz == SqlSplittableAggFunction.class) { + return clazz.cast(SqlSplittableAggFunction.SelfSplitter.INSTANCE); + } + return super.unwrap(clazz); + } +} http://git-wip-us.apache.org/repos/asf/hive/blob/1eef7e54/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java index 7208f01..13ee4e5 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java @@ -45,6 +45,7 @@ import org.apache.hadoop.hive.ql.exec.UDFArgumentException; import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException; import org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException.UnsupportedFeature; import org.apache.hadoop.hive.ql.optimizer.calcite.functions.CanAggregateDistinct; +import org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlAverageAggFunction; import org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlCountAggFunction; import org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlMinMaxAggFunction; import org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlSumAggFunction; @@ -548,6 +549,12 @@ public class SqlFunctionConverter { udfInfo.operandTypeInference, udfInfo.operandTypeChecker, false); break; + case "avg": + calciteAggFn = new HiveSqlAverageAggFunction( + udfInfo.returnTypeInference, + udfInfo.operandTypeInference, + udfInfo.operandTypeChecker); + break; default: calciteAggFn = new CalciteUDAF( isDistinct,