Search in sources :

Example 1 with RexNodeConverter

use of org.apache.hadoop.hive.ql.optimizer.calcite.translator.RexNodeConverter in project hive by apache.

the class HiveRexExecutorImpl method reduce.

@Override
public void reduce(RexBuilder rexBuilder, List<RexNode> constExps, List<RexNode> reducedValues) {
    RexNodeConverter rexNodeConverter = new RexNodeConverter(cluster);
    for (RexNode rexNode : constExps) {
        // initialize the converter
        ExprNodeConverter converter = new ExprNodeConverter("", null, null, null, new HashSet<Integer>(), cluster.getTypeFactory());
        // convert RexNode to ExprNodeGenericFuncDesc
        ExprNodeDesc expr = rexNode.accept(converter);
        if (expr instanceof ExprNodeGenericFuncDesc) {
            // folding the constant
            ExprNodeDesc constant = ConstantPropagateProcFactory.foldExpr((ExprNodeGenericFuncDesc) expr);
            if (constant != null) {
                try {
                    // convert constant back to RexNode
                    reducedValues.add(rexNodeConverter.convert((ExprNodeConstantDesc) constant));
                } catch (Exception e) {
                    LOG.warn(e.getMessage());
                    reducedValues.add(rexNode);
                }
            } else {
                reducedValues.add(rexNode);
            }
        } else {
            reducedValues.add(rexNode);
        }
    }
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) RexNodeConverter(org.apache.hadoop.hive.ql.optimizer.calcite.translator.RexNodeConverter) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) RexNode(org.apache.calcite.rex.RexNode) ExprNodeConverter(org.apache.hadoop.hive.ql.optimizer.calcite.translator.ExprNodeConverter)

Aggregations

RexNode (org.apache.calcite.rex.RexNode)1 ExprNodeConverter (org.apache.hadoop.hive.ql.optimizer.calcite.translator.ExprNodeConverter)1 RexNodeConverter (org.apache.hadoop.hive.ql.optimizer.calcite.translator.RexNodeConverter)1 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)1