use of org.apache.carbondata.core.scan.expression.BinaryExpression 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();
}
}
use of org.apache.carbondata.core.scan.expression.BinaryExpression 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);
}
}
Aggregations