Skip to content

Commit

Permalink
[#FLINK-33596] Fold expression before transfer function to RexNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunfan123 committed Nov 20, 2023
1 parent 15a3372 commit f4f8a99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.apache.hadoop.hive.common.type.HiveVarchar;
import org.apache.hadoop.hive.ql.ErrorMsg;
import org.apache.hadoop.hive.ql.exec.FunctionRegistry;
import org.apache.hadoop.hive.ql.optimizer.ConstantPropagateProcFactory;
import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
Expand Down Expand Up @@ -211,7 +212,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) {
Expand Down Expand Up @@ -518,13 +519,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<RexNode> childRexNodeLst = new ArrayList<>();
List<RelDataType> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

0 comments on commit f4f8a99

Please sign in to comment.