Search in sources :

Example 1 with StartsWithExpression

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

the class FilterExpressionProcessor method createFilterResolverTree.

/**
 * Pattern used : Visitor Pattern
 * Method will create filter resolver tree based on the filter expression tree,
 * in this algorithm based on the expression instance the resolvers will created
 *
 * @param expressionTree
 * @param tableIdentifier
 * @return
 */
private FilterResolverIntf createFilterResolverTree(Expression expressionTree, AbsoluteTableIdentifier tableIdentifier) {
    ExpressionType filterExpressionType = expressionTree.getFilterExpressionType();
    BinaryExpression currentExpression = null;
    switch(filterExpressionType) {
        case OR:
        case AND:
            currentExpression = (BinaryExpression) expressionTree;
            return new LogicalFilterResolverImpl(createFilterResolverTree(currentExpression.getLeft(), tableIdentifier), createFilterResolverTree(currentExpression.getRight(), tableIdentifier), currentExpression);
        case RANGE:
            return getFilterResolverBasedOnExpressionType(ExpressionType.RANGE, true, expressionTree, tableIdentifier, expressionTree);
        case EQUALS:
        case IN:
            return getFilterResolverBasedOnExpressionType(ExpressionType.EQUALS, ((BinaryConditionalExpression) expressionTree).isNull, expressionTree, tableIdentifier, expressionTree);
        case GREATERTHAN:
        case GREATERTHAN_EQUALTO:
        case LESSTHAN:
        case LESSTHAN_EQUALTO:
            return getFilterResolverBasedOnExpressionType(ExpressionType.EQUALS, true, expressionTree, tableIdentifier, expressionTree);
        case STARTSWITH:
            assert (expressionTree instanceof StartsWithExpression);
            currentExpression = (StartsWithExpression) expressionTree;
            Expression re = currentExpression.getRight();
            assert (re instanceof LiteralExpression);
            LiteralExpression literal = (LiteralExpression) re;
            String value = literal.getLiteralExpValue().toString();
            Expression left = new GreaterThanEqualToExpression(currentExpression.getLeft(), literal);
            String maxValueLimit = value.substring(0, value.length() - 1) + (char) (((int) value.charAt(value.length() - 1)) + 1);
            Expression right = new LessThanExpression(currentExpression.getLeft(), new LiteralExpression(maxValueLimit, literal.getLiteralExpDataType()));
            currentExpression = new AndExpression(left, right);
            return new LogicalFilterResolverImpl(createFilterResolverTree(currentExpression.getLeft(), tableIdentifier), createFilterResolverTree(currentExpression.getRight(), tableIdentifier), currentExpression);
        case NOT_EQUALS:
        case NOT_IN:
            return getFilterResolverBasedOnExpressionType(ExpressionType.NOT_EQUALS, false, expressionTree, tableIdentifier, expressionTree);
        case FALSE:
            return getFilterResolverBasedOnExpressionType(ExpressionType.FALSE, false, expressionTree, tableIdentifier, expressionTree);
        case TRUE:
            return getFilterResolverBasedOnExpressionType(ExpressionType.TRUE, false, expressionTree, tableIdentifier, expressionTree);
        default:
            return getFilterResolverBasedOnExpressionType(ExpressionType.UNKNOWN, false, expressionTree, tableIdentifier, expressionTree);
    }
}
Also used : LogicalFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.LogicalFilterResolverImpl) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) ConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression) StartsWithExpression(org.apache.carbondata.core.scan.expression.conditional.StartsWithExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) OrExpression(org.apache.carbondata.core.scan.expression.logical.OrExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) LessThanExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) StartsWithExpression(org.apache.carbondata.core.scan.expression.conditional.StartsWithExpression) ExpressionType(org.apache.carbondata.core.scan.filter.intf.ExpressionType) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) LessThanExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanExpression)

Aggregations

BinaryExpression (org.apache.carbondata.core.scan.expression.BinaryExpression)1 Expression (org.apache.carbondata.core.scan.expression.Expression)1 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)1 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)1 ConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression)1 GreaterThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression)1 InExpression (org.apache.carbondata.core.scan.expression.conditional.InExpression)1 LessThanExpression (org.apache.carbondata.core.scan.expression.conditional.LessThanExpression)1 StartsWithExpression (org.apache.carbondata.core.scan.expression.conditional.StartsWithExpression)1 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)1 OrExpression (org.apache.carbondata.core.scan.expression.logical.OrExpression)1 TrueExpression (org.apache.carbondata.core.scan.expression.logical.TrueExpression)1 ExpressionType (org.apache.carbondata.core.scan.filter.intf.ExpressionType)1 LogicalFilterResolverImpl (org.apache.carbondata.core.scan.filter.resolver.LogicalFilterResolverImpl)1