use of org.apache.carbondata.core.scan.filter.intf.FilterOptimizer in project carbondata by apache.
the class RangeFilterProcessorTest method createFilterTree_noChange.
@Test
public void createFilterTree_noChange() {
// Build 2nd Tree no change a < 5 and a > 20
Expression inputFilter;
boolean result = false;
ColumnExpression cola = new ColumnExpression("a", DataTypes.STRING);
cola.setDimension(true);
ColumnSchema empColumnSchema = new ColumnSchema();
empColumnSchema.setColumnName("empNameCol");
empColumnSchema.setColumnUniqueId("empNameCol");
empColumnSchema.setDimensionColumn(true);
empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
empColumnSchema.setDataType(DataTypes.STRING);
CarbonDimension empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
cola.setDimension(empDimension);
Expression greaterThan = new GreaterThanEqualToExpression(cola, new LiteralExpression("20", DataTypes.STRING));
ColumnExpression colb = new ColumnExpression("a", DataTypes.STRING);
colb.setDimension(true);
colb.setDimension(empDimension);
Expression lessThan = new LessThanEqualToExpression(colb, new LiteralExpression("05", DataTypes.STRING));
inputFilter = new AndExpression(greaterThan, lessThan);
Expression output = new AndExpression(new GreaterThanEqualToExpression(new ColumnExpression("a", DataTypes.STRING), new LiteralExpression("20", DataTypes.STRING)), new LessThanEqualToExpression(new ColumnExpression("a", DataTypes.STRING), new LiteralExpression("05", DataTypes.STRING)));
FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(inputFilter);
rangeFilterOptimizer.optimizeFilter();
result = checkBothTrees(inputFilter, output);
// no change
Assert.assertTrue(result);
}
use of org.apache.carbondata.core.scan.filter.intf.FilterOptimizer in project carbondata by apache.
the class RangeFilterProcessorTest method createFilterTree_flavor2.
@Test
public void createFilterTree_flavor2() {
// Build 3rd BTree a >= '11' or a > '12' or a <= '20' or a <= '15'
Expression inputFilter;
boolean result = false;
ColumnSchema empColumnSchema = new ColumnSchema();
empColumnSchema.setColumnName("a");
empColumnSchema.setColumnUniqueId("a");
empColumnSchema.setDimensionColumn(true);
empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
empColumnSchema.setDataType(DataTypes.STRING);
CarbonDimension empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
ColumnExpression cola1 = new ColumnExpression("a", DataTypes.STRING);
cola1.setDimension(true);
cola1.setDimension(empDimension);
ColumnExpression cola2 = new ColumnExpression("a", DataTypes.STRING);
cola2.setDimension(true);
cola2.setDimension(empDimension);
ColumnExpression cola3 = new ColumnExpression("a", DataTypes.STRING);
cola3.setDimension(true);
cola3.setDimension(empDimension);
ColumnExpression cola4 = new ColumnExpression("a", DataTypes.STRING);
cola4.setDimension(true);
cola4.setDimension(empDimension);
Expression lessThan1 = new LessThanEqualToExpression(cola1, new LiteralExpression("15", DataTypes.STRING));
Expression lessThan2 = new LessThanEqualToExpression(cola2, new LiteralExpression("20", DataTypes.STRING));
Expression greaterThan1 = new GreaterThanExpression(cola3, new LiteralExpression("12", DataTypes.STRING));
Expression greaterThan2 = new GreaterThanEqualToExpression(cola4, new LiteralExpression("11", DataTypes.STRING));
Expression Or1 = new OrExpression(new NotEqualsExpression(null, null), greaterThan2);
Expression Or2 = new OrExpression(Or1, greaterThan1);
Expression Or3 = new OrExpression(Or2, lessThan2);
inputFilter = new OrExpression(Or3, lessThan1);
// Build The output
ColumnExpression colb1 = new ColumnExpression("a", DataTypes.STRING);
cola1.setDimension(true);
cola1.setDimension(empDimension);
ColumnExpression colb2 = new ColumnExpression("a", DataTypes.STRING);
cola2.setDimension(true);
cola2.setDimension(empDimension);
ColumnExpression colb3 = new ColumnExpression("a", DataTypes.STRING);
cola3.setDimension(true);
cola3.setDimension(empDimension);
ColumnExpression colb4 = new ColumnExpression("a", DataTypes.STRING);
cola4.setDimension(true);
cola4.setDimension(empDimension);
Expression lessThanb1 = new LessThanEqualToExpression(colb1, new LiteralExpression("15", DataTypes.STRING));
Expression lessThanb2 = new LessThanEqualToExpression(colb2, new LiteralExpression("20", DataTypes.STRING));
Expression greaterThanb1 = new GreaterThanExpression(colb3, new LiteralExpression("12", DataTypes.STRING));
Expression greaterThanb2 = new GreaterThanEqualToExpression(colb4, new LiteralExpression("11", DataTypes.STRING));
Expression Orb1 = new OrExpression(new NotEqualsExpression(null, null), greaterThanb2);
Expression Orb2 = new OrExpression(Orb1, greaterThanb1);
Expression Orb3 = new OrExpression(Orb2, lessThanb2);
FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(inputFilter);
rangeFilterOptimizer.optimizeFilter();
result = checkBothTrees(inputFilter, new OrExpression(Orb3, lessThanb1));
// no change
Assert.assertTrue(result);
}
use of org.apache.carbondata.core.scan.filter.intf.FilterOptimizer in project carbondata by apache.
the class CarbonTable method processFilterExpression.
public void processFilterExpression(Expression filterExpression, boolean[] isFilterDimensions, boolean[] isFilterMeasures) {
QueryModel.processFilterExpression(this, filterExpression, isFilterDimensions, isFilterMeasures);
if (null != filterExpression) {
// Optimize Filter Expression and fit RANGE filters is conditions apply.
FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(filterExpression);
rangeFilterOptimizer.optimizeFilter();
}
}
use of org.apache.carbondata.core.scan.filter.intf.FilterOptimizer in project carbondata by apache.
the class CarbonInputFormatUtil method processFilterExpression.
public static void processFilterExpression(Expression filterExpression, CarbonTable carbonTable) {
List<CarbonDimension> dimensions = carbonTable.getDimensionByTableName(carbonTable.getFactTableName());
List<CarbonMeasure> measures = carbonTable.getMeasureByTableName(carbonTable.getFactTableName());
QueryModel.processFilterExpression(filterExpression, dimensions, measures);
if (null != filterExpression) {
// Optimize Filter Expression and fit RANGE filters is conditions apply.
FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(new FilterOptimizerBasic(), filterExpression);
rangeFilterOptimizer.optimizeFilter();
}
}
use of org.apache.carbondata.core.scan.filter.intf.FilterOptimizer in project carbondata by apache.
the class RangeFilterProcessorTest method createFilterTree_flavor1.
@Test
public void createFilterTree_flavor1() {
// Build 3rd BTree a >= '11' and a > '12' and a <= '20' and a <= '15'
Expression inputFilter;
boolean result = false;
ColumnSchema empColumnSchema = new ColumnSchema();
empColumnSchema.setColumnName("a");
empColumnSchema.setColumnUniqueId("a");
empColumnSchema.setDimensionColumn(true);
empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
empColumnSchema.setDataType(DataTypes.STRING);
CarbonDimension empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
ColumnExpression cola1 = new ColumnExpression("a", DataTypes.STRING);
cola1.setDimension(true);
cola1.setDimension(empDimension);
ColumnExpression cola2 = new ColumnExpression("a", DataTypes.STRING);
cola2.setDimension(true);
cola2.setDimension(empDimension);
ColumnExpression cola3 = new ColumnExpression("a", DataTypes.STRING);
cola3.setDimension(true);
cola3.setDimension(empDimension);
ColumnExpression cola4 = new ColumnExpression("a", DataTypes.STRING);
cola4.setDimension(true);
cola4.setDimension(empDimension);
Expression lessThan1 = new LessThanEqualToExpression(cola1, new LiteralExpression("15", DataTypes.STRING));
Expression lessThan2 = new LessThanEqualToExpression(cola2, new LiteralExpression("20", DataTypes.STRING));
Expression greaterThan1 = new GreaterThanExpression(cola3, new LiteralExpression("12", DataTypes.STRING));
Expression greaterThan2 = new GreaterThanEqualToExpression(cola4, new LiteralExpression("11", DataTypes.STRING));
Expression And1 = new AndExpression(new NotEqualsExpression(null, null), greaterThan2);
Expression And2 = new AndExpression(And1, greaterThan1);
Expression And3 = new AndExpression(And2, lessThan2);
inputFilter = new AndExpression(And3, lessThan1);
// Build The output
ColumnExpression colb1 = new ColumnExpression("a", DataTypes.STRING);
cola1.setDimension(true);
cola1.setDimension(empDimension);
ColumnExpression colb2 = new ColumnExpression("a", DataTypes.STRING);
cola2.setDimension(true);
cola2.setDimension(empDimension);
Expression greaterThanb1 = new GreaterThanExpression(cola3, new LiteralExpression("12", DataTypes.STRING));
Expression lessThanb1 = new LessThanEqualToExpression(cola1, new LiteralExpression("15", DataTypes.STRING));
Expression Andb1 = new AndExpression(new NotEqualsExpression(null, null), new TrueExpression(null));
Expression Andb2 = new AndExpression(Andb1, new RangeExpression(greaterThanb1, lessThanb1));
Expression Andb3 = new AndExpression(Andb2, new TrueExpression(null));
FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(inputFilter);
rangeFilterOptimizer.optimizeFilter();
result = checkBothTrees(inputFilter, new AndExpression(Andb3, new TrueExpression(null)));
// no change
Assert.assertTrue(result);
}
Aggregations