Search in sources :

Example 1 with RangeExpression

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;
    }
}
Also used : ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression)

Example 2 with RangeExpression

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);
}
Also used : DimColumnFilterInfo(org.apache.carbondata.core.scan.filter.DimColumnFilterInfo) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ArrayList(java.util.ArrayList) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 3 with RangeExpression

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));
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) OrExpression(org.apache.carbondata.core.scan.expression.logical.OrExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) GreaterThanExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression) LessThanExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with RangeExpression

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;
}
Also used : LessThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression) OrExpression(org.apache.carbondata.core.scan.expression.logical.OrExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) GreaterThanExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression) LessThanExpression(org.apache.carbondata.core.scan.expression.conditional.LessThanExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) GreaterThanEqualToExpression(org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) ExpressionType(org.apache.carbondata.core.scan.filter.intf.ExpressionType)

Example 5 with RangeExpression

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);
    }
}
Also used : DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ArrayList(java.util.ArrayList) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Aggregations

RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)9 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)5 Expression (org.apache.carbondata.core.scan.expression.Expression)4 GreaterThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanEqualToExpression)4 GreaterThanExpression (org.apache.carbondata.core.scan.expression.conditional.GreaterThanExpression)4 LessThanEqualToExpression (org.apache.carbondata.core.scan.expression.conditional.LessThanEqualToExpression)4 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)4 OrExpression (org.apache.carbondata.core.scan.expression.logical.OrExpression)4 TrueExpression (org.apache.carbondata.core.scan.expression.logical.TrueExpression)4 ArrayList (java.util.ArrayList)3 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)3 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)2 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)2 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)2 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)2 ConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression)2 LessThanExpression (org.apache.carbondata.core.scan.expression.conditional.LessThanExpression)2 NotEqualsExpression (org.apache.carbondata.core.scan.expression.conditional.NotEqualsExpression)2 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)2 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)2