use of org.apache.carbondata.core.scan.expression.logical.RangeExpression 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.logical.RangeExpression in project carbondata by apache.
the class RangeNoDictionaryTypeVisitor method populateFilterResolvedInfo.
/**
* Visitor Method will update the filter related details in visitableObj, For no dictionary
* type columns the filter members will resolved directly, no need to look up in dictionary
* since it will not be part of dictionary, directly the actual data can be converted as
* byte[] and can be set. this type of encoding is effective when the particular column
* is having very high cardinality.
*
* @param visitableObj
* @param metadata
* @throws FilterUnsupportedException,if exception occurs while evaluating
* filter models.
*/
public void populateFilterResolvedInfo(DimColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
DimColumnFilterInfo resolvedFilterObject = null;
List<ExpressionResult> listOfExpressionResults = new ArrayList<ExpressionResult>(20);
List<String> evaluateResultListFinal = new ArrayList<String>();
try {
// Add The Range Filter Values.
if (metadata.getExpression() instanceof RangeExpression) {
listOfExpressionResults = ((RangeExpression) metadata.getExpression()).getLiterals();
}
for (ExpressionResult result : listOfExpressionResults) {
if (result.getString() == null) {
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
continue;
}
evaluateResultListFinal.add(result.getString());
}
// evaluateResultListFinal.add(metadata.getExpression().evaluate().getListAsString());
if (!metadata.isIncludeFilter() && !evaluateResultListFinal.contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
}
} catch (FilterIllegalMemberException e) {
throw new FilterUnsupportedException(e);
}
resolvedFilterObject = FilterUtil.getNoDictionaryValKeyMemberForFilter(evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDataType());
visitableObj.setFilterValues(resolvedFilterObject);
}
use of org.apache.carbondata.core.scan.expression.logical.RangeExpression in project carbondata by apache.
the class RangeExpressionEvaluator method replaceWithRangeExpression.
public void replaceWithRangeExpression(Map<String, List<FilterModificationNode>> filterExpressionMap) {
List<FilterModificationNode> deleteExp = new ArrayList<>();
Iterator<Map.Entry<String, List<FilterModificationNode>>> iterator = filterExpressionMap.entrySet().iterator();
Map.Entry<String, List<FilterModificationNode>> nextEntry = null;
while (iterator.hasNext()) {
nextEntry = iterator.next();
List<FilterModificationNode> filterExp = nextEntry.getValue();
if (filterExp.size() > 1) {
// There are multiple Expression for the same column traverse and check if they can
// form a range.
FilterModificationNode startMin = null;
FilterModificationNode endMax = null;
for (FilterModificationNode exp : filterExp) {
if ((exp.getExpType() == GREATERTHAN) || (exp.getExpType() == GREATERTHAN_EQUALTO)) {
if ((null == endMax) || ((checkLiteralValue(exp.getCurrentExp(), endMax.getCurrentExp())))) {
if (null == startMin) {
startMin = exp;
} else {
// There is already some value in startMin so check which one is greater.
LiteralExpression srcLiteral = getChildLiteralExpression(startMin.getCurrentExp());
LiteralExpression tarLiteral = getChildLiteralExpression(exp.getCurrentExp());
ExpressionResult srcExpResult = srcLiteral.evaluate(null);
ExpressionResult tarExpResult = tarLiteral.evaluate(null);
if (srcExpResult.compareTo(tarExpResult) < 0) {
// Before replacing the startMin add the current StartMin into deleteExp List
// as they will be replaced with TRUE expression after RANGE formation.
deleteExp.add(startMin);
startMin = exp;
}
}
}
}
if ((exp.getExpType() == LESSTHAN) || (exp.getExpType() == LESSTHAN_EQUALTO)) {
if ((null == startMin) || ((checkLiteralValue(exp.getCurrentExp(), startMin.getCurrentExp())))) {
if (null == endMax) {
endMax = exp;
} else {
// There is already some value in endMax so check which one is less.
LiteralExpression srcLiteral = getChildLiteralExpression(endMax.getCurrentExp());
LiteralExpression tarLiteral = getChildLiteralExpression(exp.getCurrentExp());
ExpressionResult srcExpResult = srcLiteral.evaluate(null);
ExpressionResult tarExpResult = tarLiteral.evaluate(null);
if (srcExpResult.compareTo(tarExpResult) > 0) {
// Before replacing the endMax add the current endMax into deleteExp List
// as they will be replaced with TRUE expression after RANGE formation.
deleteExp.add(endMax);
endMax = exp;
}
}
}
}
}
if ((null != startMin) && (null != endMax)) {
LOG.info("GreaterThan and LessThan Filter Expression changed to Range Expression for column " + nextEntry.getKey());
// the node can be converted to RANGE.
Expression n1 = startMin.getCurrentExp();
Expression n2 = endMax.getCurrentExp();
RangeExpression rangeTree = new RangeExpression(n1, n2);
Expression srcParentNode = startMin.getParentExp();
Expression tarParentNode = endMax.getParentExp();
srcParentNode.findAndSetChild(startMin.getCurrentExp(), rangeTree);
tarParentNode.findAndSetChild(endMax.getCurrentExp(), new TrueExpression(null));
if (deleteExp.size() > 0) {
// There are some expression to Delete as they are Redundant after Range Formation.
for (FilterModificationNode trueExp : deleteExp) {
trueExp.getParentExp().findAndSetChild(trueExp.getCurrentExp(), new TrueExpression(null));
}
}
}
}
}
}
use of org.apache.carbondata.core.scan.expression.logical.RangeExpression in project carbondata by apache.
the class RangeExpressionEvaluator method traverseTree.
/**
* This Method Traverses the Expression Tree to find the corresponding node of the Range
* Expression. If one node of Range Expression is LessThan then a corresponding GreaterThan
* will be choosen or vice versa.
*
* @param currentNode
* @param parentNode
* @return
*/
private Expression traverseTree(Expression currentNode, Expression parentNode) {
Expression result = null;
if (null == parentNode) {
currentNode = this.getExpr();
parentNode = currentNode;
}
if (!this.getSrcNode().equals(currentNode) && isLessThanGreaterThanExp(currentNode)) {
String srcColumnName = getColumnName(this.getSrcNode());
String tarColumnName = getColumnName(currentNode);
ExpressionType srcExpType = getExpressionType(this.getSrcNode());
ExpressionType tarExpType = getExpressionType(currentNode);
if ((null != srcColumnName) && (null != tarColumnName) && (srcColumnName.equals(tarColumnName)) && (srcExpType != ExpressionType.FALSE) && (tarExpType != ExpressionType.FALSE) && ((matchExpType(srcExpType, tarExpType)) && checkLiteralValue(this.getSrcNode(), currentNode))) {
this.setTarNode(currentNode);
this.setTarParentNode(parentNode);
return parentNode;
}
}
for (Expression exp : currentNode.getChildren()) {
if (null != exp && !(exp instanceof RangeExpression)) {
result = traverseTree(exp, currentNode);
if (null != result) {
return result;
}
}
}
return null;
}
use of org.apache.carbondata.core.scan.expression.logical.RangeExpression in project carbondata by apache.
the class RangeNoDictionaryTypeVisitor method populateFilterResolvedInfo.
/**
* Visitor Method will update the filter related details in visitableObj, For no dictionary
* type columns the filter members will resolved directly, no need to look up in dictionary
* since it will not be part of dictionary, directly the actual data can be converted as
* byte[] and can be set. this type of encoding is effective when the particular column
* is having very high cardinality.
*
* @param visitableObj
* @param metadata
* @throws FilterUnsupportedException,if exception occurs while evaluating
* filter models.
*/
public void populateFilterResolvedInfo(ColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
if (visitableObj instanceof DimColumnResolvedFilterInfo) {
DimColumnResolvedFilterInfo resolveDimension = (DimColumnResolvedFilterInfo) visitableObj;
ColumnFilterInfo resolvedFilterObject = null;
List<ExpressionResult> listOfExpressionResults = new ArrayList<ExpressionResult>(20);
List<String> evaluateResultListFinal = new ArrayList<String>();
try {
// Add The Range Filter Values.
if (metadata.getExpression() instanceof RangeExpression) {
listOfExpressionResults = ((RangeExpression) metadata.getExpression()).getLiterals();
}
for (ExpressionResult result : listOfExpressionResults) {
if (result.getString() == null) {
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
continue;
}
evaluateResultListFinal.add(result.getString());
}
// evaluateResultListFinal.add(metadata.getExpression().evaluate().getListAsString());
if (!metadata.isIncludeFilter() && !evaluateResultListFinal.contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
}
} catch (FilterIllegalMemberException e) {
throw new FilterUnsupportedException(e);
}
resolvedFilterObject = FilterUtil.getNoDictionaryValKeyMemberForFilter(evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDataType());
resolveDimension.setFilterValues(resolvedFilterObject);
}
}
Aggregations