Search in sources :

Example 1 with ColumnExpression

use of org.apache.carbondata.core.scan.expression.ColumnExpression 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 ColumnExpression

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

the class BinaryLogicalExpression method getColumnList.

private void getColumnList(Expression expression, List<ColumnExpression> lst) {
    if (expression instanceof ColumnExpression) {
        ColumnExpression colExp = (ColumnExpression) expression;
        boolean found = false;
        for (ColumnExpression currentColExp : lst) {
            if (currentColExp.getColumnName().equals(colExp.getColumnName())) {
                found = true;
                colExp.setColIndex(currentColExp.getColIndex());
                break;
            }
        }
        if (!found) {
            colExp.setColIndex(lst.size());
            lst.add(colExp);
        }
    }
    for (Expression child : expression.getChildren()) {
        getColumnList(child, lst);
    }
}
Also used : Expression(org.apache.carbondata.core.scan.expression.Expression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression)

Example 3 with ColumnExpression

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

the class ConditionalFilterResolverImpl method isColDictionary.

private boolean isColDictionary() {
    RangeExpression condExp = (RangeExpression) exp;
    List<ColumnExpression> columnList = condExp.getColumnList();
    if (columnList.get(0).getDimension().hasEncoding(Encoding.DICTIONARY)) {
        if (columnList.get(0).getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}
Also used : ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression)

Example 4 with ColumnExpression

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

the class EqualToExpressionUnitTest method testEvaluateForEqualToExpressionWithBooleanParameter.

@Test
public void testEvaluateForEqualToExpressionWithBooleanParameter() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
    right.setColIndex(0);
    equalToExpression = new EqualToExpression(right, right, true);
    RowImpl value = new RowImpl();
    Short[] row = { 15 };
    Object[] objectRow = { row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        @Mock
        public Short getShort() {
            return 15;
        }
    };
    ExpressionResult result = equalToExpression.evaluate(value);
    assertTrue(result.getBoolean());
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 5 with ColumnExpression

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

the class EqualToExpressionUnitTest method testForEqualToExpressionForDefaultCase.

@Test(expected = FilterUnsupportedException.class)
public void testForEqualToExpressionForDefaultCase() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN);
    right.setColIndex(0);
    equalToExpression = new EqualToExpression(right, right);
    RowImpl value = new RowImpl();
    Boolean[] row = { true };
    Object[] objectRow = { row };
    value.setValues(objectRow);
    ExpressionResult result = equalToExpression.evaluate(value);
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) Test(org.junit.Test)

Aggregations

ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)119 Test (org.junit.Test)107 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)83 MockUp (mockit.MockUp)77 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)76 Expression (org.apache.carbondata.core.scan.expression.Expression)20 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)18 Timestamp (java.sql.Timestamp)8 DateFormat (java.text.DateFormat)8 ParseException (java.text.ParseException)8 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)8 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)8 BigDecimal (java.math.BigDecimal)7 ListExpression (org.apache.carbondata.core.scan.expression.conditional.ListExpression)7 Decimal (org.apache.spark.sql.types.Decimal)7 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)6 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)6 OrExpression (org.apache.carbondata.core.scan.expression.logical.OrExpression)6 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)6