Search in sources :

Example 6 with ColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.ColumnFilterInfo in project carbondata by apache.

the class RestructureEvaluatorImpl method isMeasureDefaultValuePresentInFilterValues.

/**
 * This method will check whether a default value for the non-existing column is present
 * in the filter values list
 *
 * @param measureColumnResolvedFilterInfo
 * @return
 */
protected boolean isMeasureDefaultValuePresentInFilterValues(MeasureColumnResolvedFilterInfo measureColumnResolvedFilterInfo) {
    boolean isDefaultValuePresentInFilterValues = false;
    ColumnFilterInfo filterValues = measureColumnResolvedFilterInfo.getFilterValues();
    CarbonMeasure measure = measureColumnResolvedFilterInfo.getMeasure();
    SerializableComparator comparator = Comparator.getComparatorByDataTypeForMeasure(measure.getDataType());
    Object defaultValue = null;
    if (null != measure.getDefaultValue()) {
        // default value for case where user gives is Null condition
        defaultValue = DataTypeUtil.getMeasureObjectFromDataType(measure.getDefaultValue(), measure.getDataType());
    }
    List<Object> measureFilterValuesList = filterValues.getMeasuresFilterValuesList();
    for (Object filterValue : measureFilterValuesList) {
        int compare = comparator.compare(defaultValue, filterValue);
        if (compare == 0) {
            isDefaultValuePresentInFilterValues = true;
            break;
        }
    }
    return isDefaultValuePresentInFilterValues;
}
Also used : SerializableComparator(org.apache.carbondata.core.util.comparator.SerializableComparator) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo)

Example 7 with ColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.ColumnFilterInfo in project carbondata by apache.

the class RowLevelRangeFilterResolverImpl method resolve.

/**
 * Method which will resolve the filter expression by converting the filter
 * member to its assigned dictionary values.
 */
public void resolve(AbsoluteTableIdentifier absoluteTableIdentifier, TableProvider tableProvider) throws FilterUnsupportedException {
    DimColumnResolvedFilterInfo dimColumnEvaluatorInfo = null;
    MeasureColumnResolvedFilterInfo msrColumnEvalutorInfo = null;
    int index = 0;
    if (exp instanceof BinaryLogicalExpression) {
        BinaryLogicalExpression conditionalExpression = (BinaryLogicalExpression) exp;
        List<ColumnExpression> columnList = conditionalExpression.getColumnList();
        for (ColumnExpression columnExpression : columnList) {
            if (columnExpression.isDimension()) {
                dimColumnEvaluatorInfo = new DimColumnResolvedFilterInfo();
                ColumnFilterInfo filterInfo = new ColumnFilterInfo();
                dimColumnEvaluatorInfo.setColumnIndex(columnExpression.getCarbonColumn().getOrdinal());
                dimColumnEvaluatorInfo.setRowIndex(index++);
                dimColumnEvaluatorInfo.setDimension(columnExpression.getDimension());
                dimColumnEvaluatorInfo.setDimensionExistsInCurrentSilce(false);
                if (columnExpression.getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                    if (!isIncludeFilter) {
                        filterInfo.setExcludeFilterList(getDirectSurrogateValues(columnExpression));
                    } else {
                        filterInfo.setFilterList(getDirectSurrogateValues(columnExpression));
                    }
                } else {
                    filterInfo.setFilterListForNoDictionaryCols(getNoDictionaryRangeValues());
                }
                filterInfo.setIncludeFilter(isIncludeFilter);
                dimColumnEvaluatorInfo.setFilterValues(filterInfo);
                dimColumnEvaluatorInfo.addDimensionResolvedFilterInstance(columnExpression.getDimension(), filterInfo);
                dimColEvaluatorInfoList.add(dimColumnEvaluatorInfo);
            } else {
                msrColumnEvalutorInfo = new MeasureColumnResolvedFilterInfo();
                ColumnFilterInfo filterInfo = new ColumnFilterInfo();
                msrColumnEvalutorInfo.setMeasure(columnExpression.getMeasure());
                msrColumnEvalutorInfo.setRowIndex(index++);
                msrColumnEvalutorInfo.setCarbonColumn(columnExpression.getCarbonColumn());
                msrColumnEvalutorInfo.setColumnIndex(columnExpression.getCarbonColumn().getOrdinal());
                msrColumnEvalutorInfo.setType(columnExpression.getCarbonColumn().getDataType());
                msrColumnEvalutorInfo.setMeasureExistsInCurrentSilce(false);
                filterInfo.setMeasuresFilterValuesList(getMeasureRangeValues(columnExpression.getMeasure()));
                filterInfo.setIncludeFilter(isIncludeFilter);
                msrColumnEvalutorInfo.setFilterValues(filterInfo);
                msrColumnEvalutorInfo.addMeasureResolvedFilterInstance(columnExpression.getMeasure(), filterInfo);
                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) BinaryLogicalExpression(org.apache.carbondata.core.scan.expression.logical.BinaryLogicalExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo)

Example 8 with ColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.ColumnFilterInfo in project carbondata by apache.

the class RangeDictionaryColumnVisitor method populateFilterResolvedInfo.

/**
 * This Visitor method is used to populate the visitableObj with direct dictionary filter details
 * where the filters values will be resolve using dictionary cache.
 *
 * @param visitableObj
 * @param metadata
 * @throws FilterUnsupportedException,if exception occurs while evaluating
 *                                       filter models.
 * @throws IOException
 * @throws FilterUnsupportedException
 */
public void populateFilterResolvedInfo(ColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException, IOException {
    if (visitableObj instanceof DimColumnResolvedFilterInfo) {
        DimColumnResolvedFilterInfo resolveDimension = (DimColumnResolvedFilterInfo) visitableObj;
        ColumnFilterInfo resolvedFilterObject = null;
        resolvedFilterObject = FilterUtil.getFilterListForAllValues(metadata.getTableIdentifier(), metadata.getExpression(), metadata.getColumnExpression(), metadata.isIncludeFilter(), metadata.getTableProvider(), true);
        if (!metadata.isIncludeFilter() && null != resolvedFilterObject) {
            // displaying the report as per hive compatibility.
            if (!resolvedFilterObject.getExcludeFilterList().contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY)) {
                resolvedFilterObject.getExcludeFilterList().add(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY);
                Collections.sort(resolvedFilterObject.getFilterList());
            }
        }
        resolveDimension.setFilterValues(resolvedFilterObject);
    }
}
Also used : DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo)

Example 9 with ColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.ColumnFilterInfo in project carbondata by apache.

the class RangeDirectDictionaryVisitor method populateFilterResolvedInfo.

/**
 * This Visitor method is used to populate the visitableObj with direct dictionary filter details
 * where the filters values will be resolve using dictionary cache.
 *
 * @param visitableObj
 * @param metadata
 * @throws FilterUnsupportedException,if exception occurs while evaluating
 * filter models.
 * @throws FilterUnsupportedException
 */
public void populateFilterResolvedInfo(ColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
    if (visitableObj instanceof DimColumnResolvedFilterInfo) {
        DimColumnResolvedFilterInfo resolveDimension = (DimColumnResolvedFilterInfo) visitableObj;
        ColumnFilterInfo resolvedFilterObject = null;
        List<ExpressionResult> listOfExpressionResults = null;
        List<String> evaluateResultListFinal = new ArrayList<String>();
        try {
            listOfExpressionResults = ((RangeExpression) metadata.getExpression()).getLiterals();
            for (ExpressionResult result : listOfExpressionResults) {
                if (result.getString() == null) {
                    evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
                    continue;
                }
                evaluateResultListFinal.add(result.getString());
            }
        } catch (FilterIllegalMemberException e) {
            throw new FilterUnsupportedException(e);
        }
        resolvedFilterObject = getDirectDictionaryValKeyMemberForFilter(metadata.getColumnExpression(), evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDimension().getDataType());
        if (!metadata.isIncludeFilter() && null != resolvedFilterObject && !resolvedFilterObject.getExcludeFilterList().contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY)) {
            // Adding default surrogate key of null member inorder to not display the same while
            // displaying the report as per hive compatibility.
            resolvedFilterObject.getExcludeFilterList().add(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY);
            Collections.sort(resolvedFilterObject.getExcludeFilterList());
        }
        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) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 10 with ColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.ColumnFilterInfo in project carbondata by apache.

the class CustomTypeDictionaryVisitor method populateFilterResolvedInfo.

/**
 * This Visitor method is been used to resolve or populate the filter details
 * by using custom type dictionary value, the filter membrers will be resolved using
 * custom type function which will generate dictionary for the direct column type filter members
 *
 * @param visitableObj
 * @param metadata
 * @throws FilterUnsupportedException,if exception occurs while evaluating
 *                                       filter models.
 */
public void populateFilterResolvedInfo(ColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
    ColumnFilterInfo resolvedFilterObject = null;
    if (visitableObj instanceof DimColumnResolvedFilterInfo) {
        DimColumnResolvedFilterInfo resolveDimension = (DimColumnResolvedFilterInfo) visitableObj;
        List<String> evaluateResultListFinal;
        try {
            evaluateResultListFinal = metadata.getExpression().evaluate(null).getListAsString();
        } catch (FilterIllegalMemberException e) {
            throw new FilterUnsupportedException(e);
        }
        resolvedFilterObject = getDirectDictionaryValKeyMemberForFilter(metadata.getColumnExpression(), evaluateResultListFinal, metadata.isIncludeFilter(), metadata.getColumnExpression().getDimension().getDataType());
        if (!metadata.isIncludeFilter() && null != resolvedFilterObject && !resolvedFilterObject.getExcludeFilterList().contains(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY)) {
            // Adding default surrogate key of null member inorder to not display the same while
            // displaying the report as per hive compatibility.
            resolvedFilterObject.getExcludeFilterList().add(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY);
            Collections.sort(resolvedFilterObject.getExcludeFilterList());
        }
        resolveDimension.setFilterValues(resolvedFilterObject);
    }
}
Also used : DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Aggregations

ColumnFilterInfo (org.apache.carbondata.core.scan.filter.ColumnFilterInfo)12 DimColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo)8 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)7 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)7 ArrayList (java.util.ArrayList)5 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)2 EqualToExpression (org.apache.carbondata.core.scan.expression.conditional.EqualToExpression)2 MeasureColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo)2 DirectDictionaryGenerator (org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryGenerator)1 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)1 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)1 QueryExecutionException (org.apache.carbondata.core.scan.executor.exception.QueryExecutionException)1 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)1 BinaryLogicalExpression (org.apache.carbondata.core.scan.expression.logical.BinaryLogicalExpression)1 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)1 SerializableComparator (org.apache.carbondata.core.util.comparator.SerializableComparator)1