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();
}
}
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);
}
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");
}
}
}
}
}
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);
}
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"));
}
Aggregations