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