diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveConcat.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveConcat.java new file mode 100644 index 0000000..36c34cc --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveConcat.java @@ -0,0 +1,35 @@ +/* + * 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.reloperators; + +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.type.InferTypes; +import org.apache.calcite.sql.type.ReturnTypes; + +public class HiveConcat extends SqlSpecialOperator { + public static final SqlSpecialOperator INSTANCE = new HiveConcat(); + + private HiveConcat() { + super("||", SqlKind.OTHER_FUNCTION, 30, true, ReturnTypes.VARCHAR_2000, + InferTypes.RETURN_TYPE, null + ); + } +} + diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveExtractDate.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveExtractDate.java index 4099733..a43f406 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveExtractDate.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveExtractDate.java @@ -22,6 +22,7 @@ import org.apache.calcite.sql.SqlFunction; import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.fun.SqlExtractFunction; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.sql.type.SqlTypeTransforms; @@ -43,7 +44,7 @@ Sets.newHashSet(YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND); private HiveExtractDate(String name) { - super(name, SqlKind.EXTRACT, + super(name, SqlKind.EXTRACT, ReturnTypes.cascade(ReturnTypes.INTEGER, SqlTypeTransforms.FORCE_NULLABLE), null, OperandTypes.INTERVALINTERVAL_INTERVALDATETIME, SqlFunctionCategory.SYSTEM); diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java index 3f2eaef..08ffbf6 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/SqlFunctionConverter.java @@ -50,6 +50,7 @@ import org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlMinMaxAggFunction; import org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlSumAggFunction; import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveBetween; +import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveConcat; import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveExtractDate; import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFloorDate; import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveIn; @@ -235,6 +236,8 @@ public static ASTNode buildAST(SqlOperator op, List children) { case CASE: case EXTRACT: case FLOOR: + case CEIL: + case LIKE: case OTHER_FUNCTION: node = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_FUNCTION, "TOK_FUNCTION"); node.addChild((ASTNode) ParseDriver.adaptor.create(hToken.type, hToken.text)); @@ -398,6 +401,44 @@ private static String getName(GenericUDF hiveUDF) { hToken(HiveParser.Identifier, "floor_minute")); registerFunction("floor_second", HiveFloorDate.SECOND, hToken(HiveParser.Identifier, "floor_second")); + registerFunction("power", SqlStdOperatorTable.POWER, hToken(HiveParser.Identifier, "power")); + registerDuplicateFunction("pow", SqlStdOperatorTable.POWER, + hToken(HiveParser.Identifier, "power") + ); + registerFunction("ceil", SqlStdOperatorTable.CEIL, hToken(HiveParser.Identifier, "ceil")); + registerDuplicateFunction("ceiling", SqlStdOperatorTable.CEIL, + hToken(HiveParser.Identifier, "ceil") + ); + registerFunction("floor", SqlStdOperatorTable.FLOOR, hToken(HiveParser.Identifier, "floor")); + registerFunction("log10", SqlStdOperatorTable.LOG10, hToken(HiveParser.Identifier, "log10")); + registerFunction("ln", SqlStdOperatorTable.LN, hToken(HiveParser.Identifier, "ln")); + registerFunction("cos", SqlStdOperatorTable.COS, hToken(HiveParser.Identifier, "cos")); + registerFunction("sin", SqlStdOperatorTable.SIN, hToken(HiveParser.Identifier, "sin")); + registerFunction("tan", SqlStdOperatorTable.TAN, hToken(HiveParser.Identifier, "tan")); + registerFunction("concat", HiveConcat.INSTANCE, + hToken(HiveParser.Identifier, "concat") + ); + registerFunction("substring", SqlStdOperatorTable.SUBSTRING, + hToken(HiveParser.Identifier, "substring") + ); + registerFunction("like", SqlStdOperatorTable.LIKE, hToken(HiveParser.Identifier, "like")); + registerFunction("exp", SqlStdOperatorTable.EXP, hToken(HiveParser.Identifier, "exp")); + registerFunction("div", SqlStdOperatorTable.DIVIDE_INTEGER, + hToken(HiveParser.DIV, "div") + ); + registerFunction("sqrt", SqlStdOperatorTable.SQRT, hToken(HiveParser.Identifier, "sqrt")); + registerFunction("lower", SqlStdOperatorTable.LOWER, hToken(HiveParser.Identifier, "lower")); + registerFunction("upper", SqlStdOperatorTable.UPPER, hToken(HiveParser.Identifier, "upper")); + registerFunction("abs", SqlStdOperatorTable.ABS, hToken(HiveParser.Identifier, "abs")); + registerFunction("character_length", SqlStdOperatorTable.CHARACTER_LENGTH, + hToken(HiveParser.Identifier, "character_length") + ); + registerFunction("char_length", SqlStdOperatorTable.CHAR_LENGTH, + hToken(HiveParser.Identifier, "char_length") + ); + registerDuplicateFunction("length", SqlStdOperatorTable.CHAR_LENGTH, + hToken(HiveParser.Identifier, "length") + ); } private void registerFunction(String name, SqlOperator calciteFn, HiveToken hiveToken) { diff --git ql/src/test/results/clientpositive/spark/subquery_in.q.out ql/src/test/results/clientpositive/spark/subquery_in.q.out index f89c146..5e48a5c 100644 --- ql/src/test/results/clientpositive/spark/subquery_in.q.out +++ ql/src/test/results/clientpositive/spark/subquery_in.q.out @@ -1827,7 +1827,7 @@ STAGE PLANS: alias: part Statistics: Num rows: 26 Data size: 3147 Basic stats: COMPLETE Column stats: NONE Filter Operator - predicate: floor(p_retailprice) is not null (type: boolean) + predicate: p_retailprice is not null (type: boolean) Statistics: Num rows: 26 Data size: 3147 Basic stats: COMPLETE Column stats: NONE Select Operator expressions: p_partkey (type: int), p_name (type: string), p_mfgr (type: string), p_brand (type: string), p_type (type: string), p_size (type: int), p_container (type: string), p_retailprice (type: double), p_comment (type: string) @@ -1890,7 +1890,7 @@ STAGE PLANS: outputColumnNames: _col1 Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE Filter Operator - predicate: floor(_col1) is not null (type: boolean) + predicate: _col1 is not null (type: boolean) Statistics: Num rows: 13 Data size: 1573 Basic stats: COMPLETE Column stats: NONE Select Operator expressions: floor(_col1) (type: bigint)