use of org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression in project carbondata by apache.
the class RowLevelRangeFilterResolverImpl method getDirectSurrogateValues.
private List<Integer> getDirectSurrogateValues(ColumnExpression columnExpression) throws FilterUnsupportedException {
List<ExpressionResult> listOfExpressionResults = new ArrayList<ExpressionResult>(20);
DirectDictionaryGenerator directDictionaryGenerator = DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator(columnExpression.getDimension().getDataType());
if (this.getFilterExpression() instanceof BinaryConditionalExpression) {
listOfExpressionResults = ((BinaryConditionalExpression) this.getFilterExpression()).getLiterals();
}
List<Integer> filterValuesList = new ArrayList<Integer>(20);
try {
// system can display inconsistent result.
for (ExpressionResult result : listOfExpressionResults) {
filterValuesList.add(directDictionaryGenerator.generateDirectSurrogateKey(result.getString(), CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT));
}
} catch (FilterIllegalMemberException e) {
throw new FilterUnsupportedException(e);
}
return filterValuesList;
}
use of org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression in project carbondata by apache.
the class ConditionalFilterResolverImpl method resolve.
/**
* This API will resolve the filter expression and generates the
* dictionaries for executing/evaluating the filter expressions in the
* executer layer.
*
* @throws FilterUnsupportedException
*/
@Override
public void resolve(AbsoluteTableIdentifier absoluteTableIdentifier, TableProvider tableProvider) throws FilterUnsupportedException, IOException {
FilterResolverMetadata metadata = new FilterResolverMetadata();
metadata.setTableIdentifier(absoluteTableIdentifier);
if ((!isExpressionResolve) && exp instanceof BinaryConditionalExpression) {
BinaryConditionalExpression binaryConditionalExpression = (BinaryConditionalExpression) exp;
Expression leftExp = binaryConditionalExpression.getLeft();
Expression rightExp = binaryConditionalExpression.getRight();
if (leftExp instanceof ColumnExpression) {
ColumnExpression columnExpression = (ColumnExpression) leftExp;
metadata.setColumnExpression(columnExpression);
metadata.setExpression(rightExp);
metadata.setIncludeFilter(isIncludeFilter);
metadata.setTableProvider(tableProvider);
// expression or not in depth.
if (FilterUtil.checkIfExpressionContainsColumn(rightExp) || FilterUtil.isExpressionNeedsToResolved(rightExp, isIncludeFilter) && (((null != columnExpression.getDimension()) && (columnExpression.getDimension().hasEncoding(Encoding.DICTIONARY) && !columnExpression.getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY))))) {
isExpressionResolve = true;
} else {
// visitors.
if (columnExpression.isMeasure()) {
msrColResolvedFilterInfo.setMeasure(columnExpression.getMeasure());
msrColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnExpression, exp), metadata);
} else {
dimColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnExpression, exp), metadata);
}
}
} else if (rightExp instanceof ColumnExpression) {
ColumnExpression columnExpression = (ColumnExpression) rightExp;
metadata.setColumnExpression(columnExpression);
metadata.setExpression(leftExp);
metadata.setIncludeFilter(isIncludeFilter);
metadata.setTableProvider(tableProvider);
if (columnExpression.getDataType().equals(DataTypes.TIMESTAMP) || columnExpression.getDataType().equals(DataTypes.DATE)) {
isExpressionResolve = true;
} else {
// expression or not in depth.
if (FilterUtil.checkIfExpressionContainsColumn(leftExp)) {
isExpressionResolve = true;
} else {
if (columnExpression.isMeasure()) {
msrColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnExpression, exp), metadata);
} else {
dimColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnExpression, exp), metadata);
}
}
}
} else {
isExpressionResolve = true;
}
}
if (isExpressionResolve && exp instanceof ConditionalExpression) {
ConditionalExpression conditionalExpression = (ConditionalExpression) exp;
List<ColumnExpression> columnList = conditionalExpression.getColumnList();
metadata.setColumnExpression(columnList.get(0));
metadata.setExpression(exp);
metadata.setIncludeFilter(isIncludeFilter);
metadata.setTableProvider(tableProvider);
if ((null != columnList.get(0).getDimension()) && (!columnList.get(0).getDimension().hasEncoding(Encoding.DICTIONARY) || columnList.get(0).getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) || (exp instanceof RangeExpression)) {
dimColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnList.get(0), exp), metadata);
} else if ((null != columnList.get(0).getDimension()) && (columnList.get(0).getDimension().hasEncoding(Encoding.DICTIONARY) && !columnList.get(0).getDimension().getDataType().isComplexType())) {
dimColResolvedFilterInfo.setFilterValues(FilterUtil.getFilterListForAllValues(absoluteTableIdentifier, exp, columnList.get(0), isIncludeFilter, tableProvider, isExpressionResolve));
dimColResolvedFilterInfo.setColumnIndex(columnList.get(0).getDimension().getOrdinal());
dimColResolvedFilterInfo.setDimension(columnList.get(0).getDimension());
} else if (columnList.get(0).isMeasure()) {
msrColResolvedFilterInfo.setMeasure(columnList.get(0).getMeasure());
msrColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnList.get(0), exp), metadata);
msrColResolvedFilterInfo.setCarbonColumn(columnList.get(0).getCarbonColumn());
msrColResolvedFilterInfo.setColumnIndex(columnList.get(0).getCarbonColumn().getOrdinal());
msrColResolvedFilterInfo.setType(columnList.get(0).getCarbonColumn().getDataType());
}
}
}
use of org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression in project carbondata by apache.
the class ConditionalFilterResolverImpl method resolve.
/**
* This API will resolve the filter expression and generates the
* dictionaries for executing/evaluating the filter expressions in the
* executer layer.
*
* @throws FilterUnsupportedException
*/
@Override
public void resolve(AbsoluteTableIdentifier absoluteTableIdentifier) throws FilterUnsupportedException, IOException {
FilterResolverMetadata metadata = new FilterResolverMetadata();
metadata.setTableIdentifier(absoluteTableIdentifier);
if ((!isExpressionResolve) && exp instanceof BinaryConditionalExpression) {
BinaryConditionalExpression binaryConditionalExpression = (BinaryConditionalExpression) exp;
Expression leftExp = binaryConditionalExpression.getLeft();
Expression rightExp = binaryConditionalExpression.getRight();
if (leftExp instanceof ColumnExpression) {
ColumnExpression columnExpression = (ColumnExpression) leftExp;
metadata.setColumnExpression(columnExpression);
metadata.setExpression(rightExp);
metadata.setIncludeFilter(isIncludeFilter);
// If imei=imei comes in filter condition then we need to
// skip processing of right expression.
// This flow has reached here assuming that this is a single
// column expression.
// we need to check if the other expression contains column
// expression or not in depth.
CarbonDimension dimension = columnExpression.getDimension();
if (FilterUtil.checkIfExpressionContainsColumn(rightExp) || FilterUtil.isExpressionNeedsToResolved(rightExp, isIncludeFilter) && dimension.hasEncoding(Encoding.DICTIONARY) && !dimension.hasEncoding(Encoding.DIRECT_DICTIONARY)) {
isExpressionResolve = true;
} else {
//Visitor pattern is been used in this scenario inorder to populate the
// dimColResolvedFilterInfo
//visitable object with filter member values based on the visitor type, currently there
//3 types of visitors custom,direct and no dictionary, all types of visitor populate
//the visitable instance as per its buisness logic which is different for all the
// visitors.
dimColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnExpression, exp), metadata);
}
} else if (rightExp instanceof ColumnExpression) {
ColumnExpression columnExpression = (ColumnExpression) rightExp;
metadata.setColumnExpression(columnExpression);
metadata.setExpression(leftExp);
metadata.setIncludeFilter(isIncludeFilter);
if (columnExpression.getDataType().equals(DataType.TIMESTAMP) || columnExpression.getDataType().equals(DataType.DATE)) {
isExpressionResolve = true;
} else {
// expression or not in depth.
if (FilterUtil.checkIfExpressionContainsColumn(leftExp)) {
isExpressionResolve = true;
} else {
dimColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnExpression, exp), metadata);
}
}
} else {
isExpressionResolve = true;
}
}
if (isExpressionResolve && exp instanceof ConditionalExpression) {
ConditionalExpression conditionalExpression = (ConditionalExpression) exp;
List<ColumnExpression> columnList = conditionalExpression.getColumnList();
metadata.setColumnExpression(columnList.get(0));
metadata.setExpression(exp);
metadata.setIncludeFilter(isIncludeFilter);
if (!columnList.get(0).getDimension().hasEncoding(Encoding.DICTIONARY) || columnList.get(0).getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY) || (exp instanceof RangeExpression)) {
dimColResolvedFilterInfo.populateFilterInfoBasedOnColumnType(FilterInfoTypeVisitorFactory.getResolvedFilterInfoVisitor(columnList.get(0), exp), metadata);
} else if (columnList.get(0).getDimension().hasEncoding(Encoding.DICTIONARY) && !(columnList.get(0).getDimension().getDataType() == org.apache.carbondata.core.metadata.datatype.DataType.STRUCT || columnList.get(0).getDimension().getDataType() == org.apache.carbondata.core.metadata.datatype.DataType.ARRAY)) {
dimColResolvedFilterInfo.setFilterValues(FilterUtil.getFilterListForAllValues(absoluteTableIdentifier, exp, columnList.get(0), isIncludeFilter));
dimColResolvedFilterInfo.setColumnIndex(columnList.get(0).getDimension().getOrdinal());
dimColResolvedFilterInfo.setDimension(columnList.get(0).getDimension());
}
}
}
use of org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression 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.BinaryConditionalExpression 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