diff --git a/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserRexNodeConverter.java b/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserRexNodeConverter.java index 5c5f67aa6..375c6c3ba 100644 --- a/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserRexNodeConverter.java +++ b/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserRexNodeConverter.java @@ -211,7 +211,7 @@ public static RexNode convert( public RexNode convert(ExprNodeDesc expr) throws SemanticException { if (expr instanceof ExprNodeGenericFuncDesc) { - return convertGenericFunc((ExprNodeGenericFuncDesc) expr); + return convertGenericFunc((ExprNodeGenericFuncDesc) expr, cluster); } else if (expr instanceof ExprNodeConstantDesc) { return convertConstant((ExprNodeConstantDesc) expr, cluster); } else if (expr instanceof ExprNodeColumnDesc) { @@ -518,13 +518,18 @@ public static RexNode convertConstant(ExprNodeConstantDesc literal, RelOptCluste return calciteLiteral; } - private RexNode convertGenericFunc(ExprNodeGenericFuncDesc func) throws SemanticException { + private RexNode convertGenericFunc(ExprNodeGenericFuncDesc func, RelOptCluster cluster) throws SemanticException { ExprNodeDesc tmpExprNode; RexNode tmpRN; List childRexNodeLst = new ArrayList<>(); List argTypes = new ArrayList<>(); + ExprNodeDesc afterFoldDesc = ConstantPropagateProcFactory.foldExpr(func); + if (afterFoldDesc instanceof ExprNodeConstantDesc) { + return convertConstant((ExprNodeConstantDesc) afterFoldDesc, cluster); + } + // TODO: 1) Expand to other functions as needed 2) What about types other than primitive. TypeInfo tgtDT = null; GenericUDF tgtUdf = func.getGenericUDF(); diff --git a/flink-connector-hive/src/test/resources/query-test/group_by.q b/flink-connector-hive/src/test/resources/query-test/group_by.q index 28f2bc778..251e8cf2c 100644 --- a/flink-connector-hive/src/test/resources/query-test/group_by.q +++ b/flink-connector-hive/src/test/resources/query-test/group_by.q @@ -31,3 +31,7 @@ select dep,count(1) from employee where salary<5000 and age>=38 and dep='Sales' select x,null as n from foo group by x,'a',null; [+I[1, null], +I[2, null], +I[3, null], +I[4, null], +I[5, null]] + +select dep, sum(salary) from employee group by dep, UNIX_TIMESTAMP(); + +[+I[Management, 12900], +I[Production, 18600], +I[Sales, 8400], +I[Service, 4100]] \ No newline at end of file