Search in sources :

Example 1 with LiteralExpression

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

the class RangeExpression method getLiteralsResult.

private void getLiteralsResult(Expression expression, List<ExpressionResult> listOfExp) {
    for (Expression child : expression.getChildren()) {
        if (child instanceof LiteralExpression) {
            ExpressionResult colExp = ((LiteralExpression) child).getExpressionResult();
            listOfExp.add(colExp);
        } else {
            getLiteralsResult(child, listOfExp);
        }
    }
}
Also used : Expression(org.apache.carbondata.core.scan.expression.Expression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression)

Example 2 with LiteralExpression

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

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

the class BinaryLogicalExpression method getExpressionResultList.

private void getExpressionResultList(Expression binaryConditionalExpression, List<ExpressionResult> listOfExp) {
    if (binaryConditionalExpression instanceof LiteralExpression) {
        ExpressionResult colExp = ((LiteralExpression) binaryConditionalExpression).getExpressionResult();
        listOfExp.add(colExp);
    }
    for (Expression child : binaryConditionalExpression.getChildren()) {
        getExpressionResultList(child, listOfExp);
    }
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) 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) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression)

Example 4 with LiteralExpression

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

the class EqualToFilterImpl method applyFilter.

@Override
public BitSet applyFilter(Partitioner partitioner) {
    BitSet partitionMap = PartitionUtil.generateBitSetBySize(partitioner.numPartitions(), false);
    if (equalTo.isNull) {
        partitionMap.set(partitioner.getPartition(null));
    } else {
        LiteralExpression literal = (LiteralExpression) equalTo.getRight();
        Object value = PartitionUtil.getDataBasedOnDataTypeForFilter(literal.getLiteralExpValue().toString(), partitionInfo.getColumnSchemaList().get(0).getDataType());
        partitionMap.set(partitioner.getPartition(value));
    }
    return partitionMap;
}
Also used : LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) BitSet(java.util.BitSet)

Example 5 with LiteralExpression

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

the class FilterUtilTest method testIsExpressionNeedsToResolvedWithDataTypeNullAndIsIncludeFilterFalse.

@Test
public void testIsExpressionNeedsToResolvedWithDataTypeNullAndIsIncludeFilterFalse() {
    boolean isIncludeFilter = false;
    Object obj = "test";
    LiteralExpression literalExpression = new LiteralExpression(obj, DataType.NULL);
    boolean result = FilterUtil.isExpressionNeedsToResolved(literalExpression, isIncludeFilter);
    assertTrue(result);
}
Also used : LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Aggregations

LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)19 Expression (org.apache.carbondata.core.scan.expression.Expression)15 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)14 Test (org.junit.Test)12 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)6 OrExpression (org.apache.carbondata.core.scan.expression.logical.OrExpression)6 EqualToExpression (org.apache.carbondata.core.scan.expression.conditional.EqualToExpression)5 GreaterThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression)5 GreaterThanExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression)5 LessThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression)5 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)4 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)4 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)4 ListExpression (org.apache.carbondata.core.scan.expression.conditional.ListExpression)4 NotEqualsExpression (org.apache.carbondata.core.scan.expression.conditional.NotEqualsExpression)4 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)4 TrueExpression (org.apache.carbondata.core.scan.expression.logical.TrueExpression)4 FilterOptimizer (org.apache.carbondata.core.scan.filter.intf.FilterOptimizer)4 FilterOptimizerBasic (org.apache.carbondata.core.scan.filter.intf.FilterOptimizerBasic)4 RangeFilterOptmizer (org.apache.carbondata.core.scan.filter.optimizer.RangeFilterOptmizer)4