Search in sources :

Example 1 with DimColumnFilterInfo

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

the class RestructureEvaluatorImpl method isDimensionDefaultValuePresentInFilterValues.

/**
   * This method will check whether a default value for the non-existing column is present
   * in the filter values list
   *
   * @param dimColumnEvaluatorInfo
   * @return
   */
protected boolean isDimensionDefaultValuePresentInFilterValues(DimColumnResolvedFilterInfo dimColumnEvaluatorInfo) {
    boolean isDefaultValuePresentInFilterValues = false;
    DimColumnFilterInfo filterValues = dimColumnEvaluatorInfo.getFilterValues();
    CarbonDimension dimension = dimColumnEvaluatorInfo.getDimension();
    byte[] defaultValue = dimension.getDefaultValue();
    if (!dimension.hasEncoding(Encoding.DICTIONARY)) {
        // 3 cases: is NUll, is Not Null and filter on default value of newly added column
        if (null == defaultValue) {
            // default value for case where user gives is Null condition
            defaultValue = CarbonCommonConstants.MEMBER_DEFAULT_VAL.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
        }
        List<byte[]> noDictionaryFilterValuesList = filterValues.getNoDictionaryFilterValuesList();
        for (byte[] filterValue : noDictionaryFilterValuesList) {
            int compare = ByteUtil.UnsafeComparer.INSTANCE.compareTo(defaultValue, filterValue);
            if (compare == 0) {
                isDefaultValuePresentInFilterValues = true;
                break;
            }
        }
    } else {
        // for dictionary and direct dictionary cases
        // 3 cases: is NUll, is Not Null and filter on default value of newly added column
        int defaultSurrogateValueToCompare = CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY;
        if (null != defaultValue) {
            defaultSurrogateValueToCompare++;
        }
        List<Integer> filterList = filterValues.getFilterList();
        for (Integer filterValue : filterList) {
            if (defaultSurrogateValueToCompare == filterValue) {
                isDefaultValuePresentInFilterValues = true;
                break;
            }
        }
    }
    return isDefaultValuePresentInFilterValues;
}
Also used : DimColumnFilterInfo(org.apache.carbondata.core.scan.filter.DimColumnFilterInfo) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 2 with DimColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.DimColumnFilterInfo 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(DimColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
    DimColumnFilterInfo resolvedFilterObject = null;
    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.getFilterList().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.getFilterList().add(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY);
        Collections.sort(resolvedFilterObject.getFilterList());
    }
    visitableObj.setFilterValues(resolvedFilterObject);
}
Also used : DimColumnFilterInfo(org.apache.carbondata.core.scan.filter.DimColumnFilterInfo) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 3 with DimColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.DimColumnFilterInfo 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(DimColumnResolvedFilterInfo visitableObj, FilterResolverMetadata metadata) throws FilterUnsupportedException {
    DimColumnFilterInfo resolvedFilterObject = null;
    List<ExpressionResult> listOfExpressionResults = new ArrayList<ExpressionResult>(20);
    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.getFilterList().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.getFilterList().add(CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY);
        Collections.sort(resolvedFilterObject.getFilterList());
    }
    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) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 4 with DimColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.DimColumnFilterInfo 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 5 with DimColumnFilterInfo

use of org.apache.carbondata.core.scan.filter.DimColumnFilterInfo 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) 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();
                DimColumnFilterInfo filterInfo = new DimColumnFilterInfo();
                dimColumnEvaluatorInfo.setColumnIndex(columnExpression.getCarbonColumn().getOrdinal());
                dimColumnEvaluatorInfo.setRowIndex(index++);
                dimColumnEvaluatorInfo.setDimension(columnExpression.getDimension());
                dimColumnEvaluatorInfo.setDimensionExistsInCurrentSilce(false);
                if (columnExpression.getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                    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();
                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) BinaryLogicalExpression(org.apache.carbondata.core.scan.expression.logical.BinaryLogicalExpression) DimColumnFilterInfo(org.apache.carbondata.core.scan.filter.DimColumnFilterInfo) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression)

Aggregations

DimColumnFilterInfo (org.apache.carbondata.core.scan.filter.DimColumnFilterInfo)9 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)5 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)5 ArrayList (java.util.ArrayList)3 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)2 DirectDictionaryGenerator (org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryGenerator)1 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)1 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)1 EqualToExpression (org.apache.carbondata.core.scan.expression.conditional.EqualToExpression)1 BinaryLogicalExpression (org.apache.carbondata.core.scan.expression.logical.BinaryLogicalExpression)1 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)1 DimColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo)1 MeasureColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo)1