Search in sources :

Example 1 with InExpression

use of org.apache.carbondata.core.scan.expression.conditional.InExpression in project carbondata by apache.

the class FilterExpressionProcessor method createPartitionFilterTree.

/**
 * create partition filter by basing on pushed-down filter
 * @param expressionTree
 * @param partitionInfo
 * @return
 */
private PartitionFilterIntf createPartitionFilterTree(Expression expressionTree, PartitionInfo partitionInfo) {
    ExpressionType filterExpressionType = expressionTree.getFilterExpressionType();
    String partitionColumnName = partitionInfo.getColumnSchemaList().get(0).getColumnName();
    BinaryExpression currentExpression = null;
    ColumnExpression left = null;
    switch(filterExpressionType) {
        case OR:
            currentExpression = (BinaryExpression) expressionTree;
            return new OrFilterImpl(createPartitionFilterTree(currentExpression.getLeft(), partitionInfo), createPartitionFilterTree(currentExpression.getRight(), partitionInfo));
        case RANGE:
        case AND:
            currentExpression = (BinaryExpression) expressionTree;
            return new AndFilterImpl(createPartitionFilterTree(currentExpression.getLeft(), partitionInfo), createPartitionFilterTree(currentExpression.getRight(), partitionInfo));
        case EQUALS:
            EqualToExpression equalTo = (EqualToExpression) expressionTree;
            if (equalTo.getLeft() instanceof ColumnExpression && equalTo.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) equalTo.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new EqualToFilterImpl(equalTo, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case IN:
            InExpression in = (InExpression) expressionTree;
            if (in.getLeft() instanceof ColumnExpression && in.getRight() instanceof ListExpression) {
                left = (ColumnExpression) in.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new InFilterImpl(in, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case FALSE:
            return new PruneAllPartitionFilterImpl();
        case TRUE:
            return new KeepAllPartitionFilterImpl();
        case GREATERTHAN:
            GreaterThanExpression greaterThan = (GreaterThanExpression) expressionTree;
            if (greaterThan.getLeft() instanceof ColumnExpression && greaterThan.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) greaterThan.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) greaterThan.getRight(), true, false, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case GREATERTHAN_EQUALTO:
            GreaterThanEqualToExpression greaterThanEqualTo = (GreaterThanEqualToExpression) expressionTree;
            if (greaterThanEqualTo.getLeft() instanceof ColumnExpression && greaterThanEqualTo.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) greaterThanEqualTo.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) greaterThanEqualTo.getRight(), true, true, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case LESSTHAN:
            LessThanExpression lessThan = (LessThanExpression) expressionTree;
            if (lessThan.getLeft() instanceof ColumnExpression && lessThan.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) lessThan.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) lessThan.getRight(), false, false, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case LESSTHAN_EQUALTO:
            LessThanEqualToExpression lessThanEqualTo = (LessThanEqualToExpression) expressionTree;
            if (lessThanEqualTo.getLeft() instanceof ColumnExpression && lessThanEqualTo.getRight() instanceof LiteralExpression) {
                left = (ColumnExpression) lessThanEqualTo.getLeft();
                if (partitionColumnName.equals(left.getCarbonColumn().getColName())) {
                    return new RangeFilterImpl((LiteralExpression) lessThanEqualTo.getRight(), false, true, partitionInfo);
                }
            }
            return new KeepAllPartitionFilterImpl();
        case NOT_IN:
        case NOT_EQUALS:
        default:
            return new KeepAllPartitionFilterImpl();
    }
}
Also used : LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) AndFilterImpl(org.apache.carbondata.core.scan.filter.partition.AndFilterImpl) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) GreaterThanExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression) LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) EqualToFilterImpl(org.apache.carbondata.core.scan.filter.partition.EqualToFilterImpl) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) KeepAllPartitionFilterImpl(org.apache.carbondata.core.scan.filter.partition.KeepAllPartitionFilterImpl) PruneAllPartitionFilterImpl(org.apache.carbondata.core.scan.filter.partition.PruneAllPartitionFilterImpl) RangeFilterImpl(org.apache.carbondata.core.scan.filter.partition.RangeFilterImpl) InFilterImpl(org.apache.carbondata.core.scan.filter.partition.InFilterImpl) ExpressionType(org.apache.carbondata.core.scan.filter.intf.ExpressionType) OrFilterImpl(org.apache.carbondata.core.scan.filter.partition.OrFilterImpl) LessThanExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanExpression)

Example 2 with InExpression

use of org.apache.carbondata.core.scan.expression.conditional.InExpression in project carbondata by apache.

the class FilterUtilTest method testRemoveInExpressionNodeWithDifferentColumn.

@Test
public void testRemoveInExpressionNodeWithDifferentColumn() {
    List<Expression> children = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    // create literal expression
    LiteralExpression literalExpression = new LiteralExpression("testName", DataTypes.STRING);
    children.add(literalExpression);
    // create list expression
    ListExpression listExpression = new ListExpression(children);
    // create column expression with column name as positionId
    ColumnExpression columnExpression = new ColumnExpression("name", DataTypes.STRING);
    // create InExpression as right node
    InExpression inExpression = new InExpression(columnExpression, listExpression);
    // create a dummy true expression as left node
    TrueExpression trueExpression = new TrueExpression(null);
    // create and expression as the root node
    Expression expression = new AndExpression(trueExpression, inExpression);
    // test remove expression method
    FilterUtil.removeInExpressionNodeWithPositionIdColumn(expression);
    // after removing the right node instance of right node should be of true expression
    assert (((AndExpression) expression).getRight() instanceof InExpression);
}
Also used : TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ArrayList(java.util.ArrayList) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Example 3 with InExpression

use of org.apache.carbondata.core.scan.expression.conditional.InExpression in project carbondata by apache.

the class FilterUtil method removeInExpressionNodeWithPositionIdColumn.

/**
 * This method will check for ColumnExpression with column name positionID and if found will
 * replace the InExpression with true expression. This is done to stop serialization of List
 * expression which is right children of InExpression as it can impact the query performance
 * as the size of list grows bigger.
 *
 * @param expression
 */
public static void removeInExpressionNodeWithPositionIdColumn(Expression expression) {
    ExpressionType filterExpressionType = expression.getFilterExpressionType();
    if (ExpressionType.AND == filterExpressionType) {
        Expression rightExpression = ((AndExpression) expression).getRight();
        if (rightExpression instanceof InExpression) {
            List<Expression> children = rightExpression.getChildren();
            if (null != children && !children.isEmpty()) {
                Expression childExpression = children.get(0);
                // check for the positionId as the column name in ColumnExpression
                if (childExpression instanceof ColumnExpression && ((ColumnExpression) childExpression).getColumnName().equalsIgnoreCase(CarbonCommonConstants.POSITION_ID)) {
                    // Remove the right expression node and point the expression to left node expression
                    expression.findAndSetChild(((AndExpression) expression).getRight(), new TrueExpression(null));
                    LOGGER.info("In expression removed from the filter expression list to prevent it from" + " serializing on executor");
                }
            }
        }
    }
}
Also used : TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ExpressionType(org.apache.carbondata.core.scan.filter.intf.ExpressionType)

Example 4 with InExpression

use of org.apache.carbondata.core.scan.expression.conditional.InExpression in project carbondata by apache.

the class FilterExpressionProcessor method getFilterResolverBasedOnExpressionType.

/**
 * Factory method which will return the resolver instance based on filter expression
 * expressions.
 */
private FilterResolverIntf getFilterResolverBasedOnExpressionType(ExpressionType filterExpressionType, boolean isExpressionResolve, Expression expression, AbsoluteTableIdentifier tableIdentifier, Expression expressionTree) {
    BinaryConditionalExpression currentCondExpression = null;
    ConditionalExpression condExpression = null;
    switch(filterExpressionType) {
        case FALSE:
            return new FalseConditionalResolverImpl(expression, false, false);
        case TRUE:
            return new TrueConditionalResolverImpl(expression, false, false);
        case EQUALS:
            currentCondExpression = (BinaryConditionalExpression) expression;
            // check for implicit column in the expression
            if (currentCondExpression instanceof InExpression) {
                CarbonColumn carbonColumn = currentCondExpression.getColumnList().get(0).getCarbonColumn();
                if (carbonColumn.hasEncoding(Encoding.IMPLICIT)) {
                    return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, currentCondExpression.getColumnList().get(0).getCarbonColumn().isMeasure());
                }
            }
            CarbonColumn column = currentCondExpression.getColumnList().get(0).getCarbonColumn();
            if (currentCondExpression.isSingleColumn() && !column.getDataType().isComplexType()) {
                if (column.isMeasure()) {
                    if (FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getLeft()) && FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getRight()) || (FilterUtil.checkIfRightExpressionRequireEvaluation(currentCondExpression.getRight()) || FilterUtil.checkIfLeftExpressionRequireEvaluation(currentCondExpression.getLeft()))) {
                        return new RowLevelFilterResolverImpl(expression, isExpressionResolve, true, tableIdentifier);
                    }
                    if (currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN_EQUALTO || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN_EQUALTO) {
                        return new RowLevelRangeFilterResolverImpl(expression, isExpressionResolve, true, tableIdentifier);
                    }
                    return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, currentCondExpression.getColumnList().get(0).getCarbonColumn().isMeasure());
                }
                // getting new dim index.
                if (!currentCondExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DICTIONARY) || currentCondExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                    if (FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getLeft()) && FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getRight()) || (FilterUtil.checkIfRightExpressionRequireEvaluation(currentCondExpression.getRight()) || FilterUtil.checkIfLeftExpressionRequireEvaluation(currentCondExpression.getLeft()))) {
                        return new RowLevelFilterResolverImpl(expression, isExpressionResolve, true, tableIdentifier);
                    }
                    if (currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN_EQUALTO || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN_EQUALTO) {
                        return new RowLevelRangeFilterResolverImpl(expression, isExpressionResolve, true, tableIdentifier);
                    }
                }
                return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, currentCondExpression.getColumnList().get(0).getCarbonColumn().isMeasure());
            }
            break;
        case RANGE:
            return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, false);
        case NOT_EQUALS:
            currentCondExpression = (BinaryConditionalExpression) expression;
            column = currentCondExpression.getColumnList().get(0).getCarbonColumn();
            if (currentCondExpression.isSingleColumn() && !column.getDataType().isComplexType()) {
                if (column.isMeasure()) {
                    if (FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getLeft()) && FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getRight()) || (FilterUtil.checkIfRightExpressionRequireEvaluation(currentCondExpression.getRight()) || FilterUtil.checkIfLeftExpressionRequireEvaluation(currentCondExpression.getLeft()))) {
                        return new RowLevelFilterResolverImpl(expression, isExpressionResolve, false, tableIdentifier);
                    }
                    if (currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN_EQUALTO || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN_EQUALTO) {
                        return new RowLevelRangeFilterResolverImpl(expression, isExpressionResolve, false, tableIdentifier);
                    }
                    return new ConditionalFilterResolverImpl(expression, isExpressionResolve, false, true);
                }
                if (!currentCondExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DICTIONARY) || currentCondExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                    if (FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getLeft()) && FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getRight()) || (FilterUtil.checkIfRightExpressionRequireEvaluation(currentCondExpression.getRight()) || FilterUtil.checkIfLeftExpressionRequireEvaluation(currentCondExpression.getLeft()))) {
                        return new RowLevelFilterResolverImpl(expression, isExpressionResolve, false, tableIdentifier);
                    }
                    if (expressionTree.getFilterExpressionType() == ExpressionType.GREATERTHAN || expressionTree.getFilterExpressionType() == ExpressionType.LESSTHAN || expressionTree.getFilterExpressionType() == ExpressionType.GREATERTHAN_EQUALTO || expressionTree.getFilterExpressionType() == ExpressionType.LESSTHAN_EQUALTO) {
                        return new RowLevelRangeFilterResolverImpl(expression, isExpressionResolve, false, tableIdentifier);
                    }
                    return new ConditionalFilterResolverImpl(expression, isExpressionResolve, false, false);
                }
                return new ConditionalFilterResolverImpl(expression, isExpressionResolve, false, false);
            }
            break;
        default:
            if (expression instanceof ConditionalExpression) {
                condExpression = (ConditionalExpression) expression;
                column = condExpression.getColumnList().get(0).getCarbonColumn();
                if (condExpression.isSingleColumn() && !column.isComplex()) {
                    condExpression = (ConditionalExpression) expression;
                    if ((condExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DICTIONARY) && !condExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DIRECT_DICTIONARY)) || (condExpression.getColumnList().get(0).getCarbonColumn().isMeasure())) {
                        return new ConditionalFilterResolverImpl(expression, true, true, condExpression.getColumnList().get(0).getCarbonColumn().isMeasure());
                    }
                }
            }
    }
    return new RowLevelFilterResolverImpl(expression, false, false, tableIdentifier);
}
Also used : ConditionalFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.ConditionalFilterResolverImpl) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) RowLevelFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.RowLevelFilterResolverImpl) ConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) RowLevelRangeFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.RowLevelRangeFilterResolverImpl) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) FalseConditionalResolverImpl(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.FalseConditionalResolverImpl) TrueConditionalResolverImpl(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.TrueConditionalResolverImpl)

Example 5 with InExpression

use of org.apache.carbondata.core.scan.expression.conditional.InExpression in project carbondata by apache.

the class FilterExpressionProcessorTest method testGetFilterResolverBasedOnExpressionType.

@Test
public void testGetFilterResolverBasedOnExpressionType() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    CarbonColumn carbonColumn = new CarbonColumn(columnSchema, 0, 0);
    ColumnExpression columnExpression = new ColumnExpression("IMEI", DataTypes.STRING);
    columnExpression.setCarbonColumn(carbonColumn);
    LiteralExpression literalExpression = new LiteralExpression("ImeiValue", DataTypes.STRING);
    InExpression equalToExpression = new InExpression(columnExpression, literalExpression);
    FilterExpressionProcessor filterExpressionProcessor = new FilterExpressionProcessor();
    Method method = FilterExpressionProcessor.class.getDeclaredMethod("getFilterResolverBasedOnExpressionType", ExpressionType.class, boolean.class, Expression.class, AbsoluteTableIdentifier.class, Expression.class);
    method.setAccessible(true);
    Object result = method.invoke(filterExpressionProcessor, ExpressionType.EQUALS, false, equalToExpression, null, null);
    Assert.assertTrue(result.getClass().getName().equals("org.apache.carbondata.core.scan.filter.resolver.ConditionalFilterResolverImpl"));
}
Also used : CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) Method(java.lang.reflect.Method) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Aggregations

InExpression (org.apache.carbondata.core.scan.expression.conditional.InExpression)7 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)6 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)6 ListExpression (org.apache.carbondata.core.scan.expression.conditional.ListExpression)5 Expression (org.apache.carbondata.core.scan.expression.Expression)4 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)4 ArrayList (java.util.ArrayList)3 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)3 TrueExpression (org.apache.carbondata.core.scan.expression.logical.TrueExpression)3 Test (org.junit.Test)3 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 Domain (com.facebook.presto.spi.predicate.Domain)1 Range (com.facebook.presto.spi.predicate.Range)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1 BigintType (com.facebook.presto.spi.type.BigintType)1 BooleanType (com.facebook.presto.spi.type.BooleanType)1 DateType (com.facebook.presto.spi.type.DateType)1 DecimalType (com.facebook.presto.spi.type.DecimalType)1 Decimals (com.facebook.presto.spi.type.Decimals)1