Search in sources :

Example 11 with GenericUDFIn

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFIn in project hive by apache.

the class RedundantDynamicPruningConditionsRemoval method collect.

private static void collect(ExprNodeDesc parent, ExprNodeDesc child, CollectContext listContext) {
    if (child instanceof ExprNodeGenericFuncDesc && ((ExprNodeGenericFuncDesc) child).getGenericUDF() instanceof GenericUDFIn) {
        if (child.getChildren().get(1) instanceof ExprNodeDynamicListDesc) {
            listContext.dynamicListNodes.add(new Pair<ExprNodeDesc, ExprNodeDesc>(child, parent));
        }
        return;
    }
    if (child instanceof ExprNodeGenericFuncDesc && ((ExprNodeGenericFuncDesc) child).getGenericUDF() instanceof GenericUDFBaseCompare && child.getChildren().size() == 2) {
        ExprNodeDesc leftCol = child.getChildren().get(0);
        ExprNodeDesc rightCol = child.getChildren().get(1);
        ExprNodeColumnDesc leftColDesc = ExprNodeDescUtils.getColumnExpr(leftCol);
        if (leftColDesc != null) {
            boolean rightConstant = false;
            if (rightCol instanceof ExprNodeConstantDesc) {
                rightConstant = true;
            } else if (rightCol instanceof ExprNodeGenericFuncDesc) {
                ExprNodeDesc foldedExpr = ConstantPropagateProcFactory.foldExpr((ExprNodeGenericFuncDesc) rightCol);
                rightConstant = foldedExpr != null;
            }
            if (rightConstant) {
                listContext.comparatorNodes.add(leftColDesc);
            }
        } else {
            ExprNodeColumnDesc rightColDesc = ExprNodeDescUtils.getColumnExpr(rightCol);
            if (rightColDesc != null) {
                boolean leftConstant = false;
                if (leftCol instanceof ExprNodeConstantDesc) {
                    leftConstant = true;
                } else if (leftCol instanceof ExprNodeGenericFuncDesc) {
                    ExprNodeDesc foldedExpr = ConstantPropagateProcFactory.foldExpr((ExprNodeGenericFuncDesc) leftCol);
                    leftConstant = foldedExpr != null;
                }
                if (leftConstant) {
                    listContext.comparatorNodes.add(rightColDesc);
                }
            }
        }
        return;
    }
    if (FunctionRegistry.isOpAnd(child)) {
        for (ExprNodeDesc newChild : child.getChildren()) {
            collect(child, newChild, listContext);
        }
    }
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) ExprNodeDynamicListDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDynamicListDesc) GenericUDFBaseCompare(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBaseCompare) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) GenericUDFIn(org.apache.hadoop.hive.ql.udf.generic.GenericUDFIn) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Example 12 with GenericUDFIn

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFIn in project carbondata by apache.

the class Hive2CarbonExpressionTest method testInHiveFilter.

@Test
public void testInHiveFilter() throws IOException {
    ExprNodeDesc column1 = new ExprNodeColumnDesc(TypeInfoFactory.intTypeInfo, "id", null, false);
    List<ExprNodeDesc> children1 = Lists.newArrayList();
    ExprNodeDesc constant1 = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, "500");
    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, "600");
    ExprNodeDesc constant3 = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, "700");
    children1.add(column1);
    children1.add(constant1);
    children1.add(constant2);
    children1.add(constant3);
    ExprNodeGenericFuncDesc node1 = new ExprNodeGenericFuncDesc(TypeInfoFactory.intTypeInfo, new GenericUDFIn(), children1);
    Configuration configuration = new Configuration();
    CarbonInputFormat.setFilterPredicates(configuration, new IndexFilter(table, Hive2CarbonExpression.convertExprHive2Carbon(node1)));
    final Job job = new Job(new JobConf(configuration));
    final CarbonFileInputFormat format = new CarbonFileInputFormat();
    format.setTableInfo(job.getConfiguration(), table.getTableInfo());
    format.setTablePath(job.getConfiguration(), table.getTablePath());
    format.setTableName(job.getConfiguration(), table.getTableName());
    format.setDatabaseName(job.getConfiguration(), table.getDatabaseName());
    List<InputSplit> list = format.getSplits(job);
    Assert.assertEquals(1, list.size());
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) Configuration(org.apache.hadoop.conf.Configuration) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) CarbonFileInputFormat(org.apache.carbondata.hadoop.api.CarbonFileInputFormat) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) GenericUDFIn(org.apache.hadoop.hive.ql.udf.generic.GenericUDFIn) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) IndexFilter(org.apache.carbondata.core.index.IndexFilter) Job(org.apache.hadoop.mapreduce.Job) JobConf(org.apache.hadoop.mapred.JobConf) InputSplit(org.apache.hadoop.mapreduce.InputSplit) Test(org.junit.Test)

Aggregations

GenericUDFIn (org.apache.hadoop.hive.ql.udf.generic.GenericUDFIn)12 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)10 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)9 ArrayList (java.util.ArrayList)8 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)7 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)7 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)7 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)6 GenericUDFBaseCompare (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBaseCompare)5 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)5 GenericUDFBetween (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBetween)4 RexNode (org.apache.calcite.rex.RexNode)3 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)3 RelDataType (org.apache.calcite.rel.type.RelDataType)2 RexCall (org.apache.calcite.rex.RexCall)2 SqlOperator (org.apache.calcite.sql.SqlOperator)2 SqlCastFunction (org.apache.calcite.sql.fun.SqlCastFunction)2 DataTypePhysicalVariation (org.apache.hadoop.hive.common.type.DataTypePhysicalVariation)2 VectorRandomBatchSource (org.apache.hadoop.hive.ql.exec.vector.VectorRandomBatchSource)2 VectorRandomRowSource (org.apache.hadoop.hive.ql.exec.vector.VectorRandomRowSource)2