Search in sources :

Example 1 with FilterResolverMetadata

use of org.apache.carbondata.core.scan.filter.resolver.metadata.FilterResolverMetadata 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());
        }
    }
}
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)

Example 2 with FilterResolverMetadata

use of org.apache.carbondata.core.scan.filter.resolver.metadata.FilterResolverMetadata 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)

Aggregations

ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)2 Expression (org.apache.carbondata.core.scan.expression.Expression)2 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)2 ConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression)2 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)2 FilterResolverMetadata (org.apache.carbondata.core.scan.filter.resolver.metadata.FilterResolverMetadata)2 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)1