Search in sources :

Example 1 with ConditionalExpression

use of org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression 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());
        }
    }
}
Also used : FilterResolverMetadata(org.apache.carbondata.core.scan.filter.resolver.metadata.FilterResolverMetadata) Expression(org.apache.carbondata.core.scan.expression.Expression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) ConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) ConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression) RangeExpression(org.apache.carbondata.core.scan.expression.logical.RangeExpression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 2 with ConditionalExpression

use of org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression in project carbondata by apache.

the class RowLevelFilterResolverImpl method resolve.

/**
   * Method which will resolve the filter expression by converting the filter member
   * to its assigned dictionary values.
   */
public void resolve(AbsoluteTableIdentifier absoluteTableIdentifier) {
    DimColumnResolvedFilterInfo dimColumnEvaluatorInfo = null;
    MeasureColumnResolvedFilterInfo msrColumnEvalutorInfo = null;
    int index = 0;
    if (exp instanceof ConditionalExpression) {
        ConditionalExpression conditionalExpression = (ConditionalExpression) exp;
        List<ColumnExpression> columnList = conditionalExpression.getColumnList();
        for (ColumnExpression columnExpression : columnList) {
            if (columnExpression.isDimension()) {
                dimColumnEvaluatorInfo = new DimColumnResolvedFilterInfo();
                dimColumnEvaluatorInfo.setColumnIndex(columnExpression.getCarbonColumn().getOrdinal());
                dimColumnEvaluatorInfo.setRowIndex(index++);
                dimColumnEvaluatorInfo.setDimension(columnExpression.getDimension());
                dimColumnEvaluatorInfo.setDimensionExistsInCurrentSilce(false);
                dimColEvaluatorInfoList.add(dimColumnEvaluatorInfo);
            } else {
                msrColumnEvalutorInfo = new MeasureColumnResolvedFilterInfo();
                msrColumnEvalutorInfo.setCarbonColumn(columnExpression.getCarbonColumn());
                msrColumnEvalutorInfo.setRowIndex(index++);
                msrColumnEvalutorInfo.setColumnIndex(columnExpression.getCarbonColumn().getOrdinal());
                msrColumnEvalutorInfo.setType(columnExpression.getCarbonColumn().getDataType());
                msrColEvalutorInfoList.add(msrColumnEvalutorInfo);
            }
        }
    }
}
Also used : MeasureColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo) DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) ConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression)

Example 3 with ConditionalExpression

use of org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression 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 RowLevelFilterResolverImpl(expression, false, false, tableIdentifier);
        case TRUE:
            return new TrueConditionalResolverImpl(expression, false, false, tableIdentifier);
        case EQUALS:
            currentCondExpression = (BinaryConditionalExpression) expression;
            if (currentCondExpression.isSingleDimension() && currentCondExpression.getColumnList().get(0).getCarbonColumn().getDataType() != DataType.ARRAY && currentCondExpression.getColumnList().get(0).getCarbonColumn().getDataType() != DataType.STRUCT) {
                // 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, tableIdentifier);
            }
            break;
        case RANGE:
            return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, tableIdentifier);
        case NOT_EQUALS:
            currentCondExpression = (BinaryConditionalExpression) expression;
            if (currentCondExpression.isSingleDimension() && currentCondExpression.getColumnList().get(0).getCarbonColumn().getDataType() != DataType.ARRAY && currentCondExpression.getColumnList().get(0).getCarbonColumn().getDataType() != DataType.STRUCT) {
                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, tableIdentifier);
                }
                return new ConditionalFilterResolverImpl(expression, isExpressionResolve, false, tableIdentifier);
            }
            break;
        default:
            if (expression instanceof ConditionalExpression) {
                condExpression = (ConditionalExpression) expression;
                if (condExpression.isSingleDimension() && condExpression.getColumnList().get(0).getCarbonColumn().getDataType() != DataType.ARRAY && condExpression.getColumnList().get(0).getCarbonColumn().getDataType() != DataType.STRUCT) {
                    condExpression = (ConditionalExpression) expression;
                    if (condExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DICTIONARY) && !condExpression.getColumnList().get(0).getCarbonColumn().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                        return new ConditionalFilterResolverImpl(expression, true, true, tableIdentifier);
                    }
                }
            }
    }
    return new RowLevelFilterResolverImpl(expression, false, false, tableIdentifier);
}
Also used : ConditionalFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.ConditionalFilterResolverImpl) RowLevelFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.RowLevelFilterResolverImpl) ConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) RowLevelRangeFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.RowLevelRangeFilterResolverImpl) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) TrueConditionalResolverImpl(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.TrueConditionalResolverImpl)

Aggregations

ConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression)3 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)2 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)2 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)1 Expression (org.apache.carbondata.core.scan.expression.Expression)1 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)1 ConditionalFilterResolverImpl (org.apache.carbondata.core.scan.filter.resolver.ConditionalFilterResolverImpl)1 RowLevelFilterResolverImpl (org.apache.carbondata.core.scan.filter.resolver.RowLevelFilterResolverImpl)1 RowLevelRangeFilterResolverImpl (org.apache.carbondata.core.scan.filter.resolver.RowLevelRangeFilterResolverImpl)1 FilterResolverMetadata (org.apache.carbondata.core.scan.filter.resolver.metadata.FilterResolverMetadata)1 DimColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo)1 MeasureColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo)1 TrueConditionalResolverImpl (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.TrueConditionalResolverImpl)1