Search in sources :

Example 6 with FilterIllegalMemberException

use of org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException 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 7 with FilterIllegalMemberException

use of org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException 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 8 with FilterIllegalMemberException

use of org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException 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 9 with FilterIllegalMemberException

use of org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException in project carbondata by apache.

the class FilterUtil method getFilterListForAllMembersRS.

/**
   * This method will get the member based on filter expression evaluation from the
   * forward dictionary cache, this method will be basically used in restructure.
   *
   * @param expression
   * @param columnExpression
   * @param defaultValues
   * @param defaultSurrogate
   * @param isIncludeFilter
   * @return
   * @throws FilterUnsupportedException
   */
public static DimColumnFilterInfo getFilterListForAllMembersRS(Expression expression, ColumnExpression columnExpression, String defaultValues, int defaultSurrogate, boolean isIncludeFilter) throws FilterUnsupportedException {
    List<Integer> filterValuesList = new ArrayList<Integer>(20);
    List<String> evaluateResultListFinal = new ArrayList<String>(20);
    DimColumnFilterInfo columnFilterInfo = null;
    // KeyGeneratorFactory.getKeyGenerator(new int[] { defaultSurrogate });
    try {
        RowIntf row = new RowImpl();
        if (defaultValues.equals(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
            defaultValues = null;
        }
        row.setValues(new Object[] { DataTypeUtil.getDataBasedOnDataType(defaultValues, columnExpression.getCarbonColumn().getDataType()) });
        Boolean rslt = expression.evaluate(row).getBoolean();
        if (null != rslt && rslt == isIncludeFilter) {
            if (null == defaultValues) {
                evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
            } else {
                evaluateResultListFinal.add(defaultValues);
            }
        }
    } catch (FilterIllegalMemberException e) {
        LOGGER.audit(e.getMessage());
    }
    if (null == defaultValues) {
        defaultValues = CarbonCommonConstants.MEMBER_DEFAULT_VAL;
    }
    columnFilterInfo = new DimColumnFilterInfo();
    for (int i = 0; i < evaluateResultListFinal.size(); i++) {
        if (evaluateResultListFinal.get(i).equals(defaultValues)) {
            filterValuesList.add(defaultSurrogate);
            break;
        }
    }
    columnFilterInfo.setFilterList(filterValuesList);
    return columnFilterInfo;
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ArrayList(java.util.ArrayList) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 10 with FilterIllegalMemberException

use of org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException in project carbondata by apache.

the class FilterUtil method getFilterListForAllValues.

/**
   * This method will get all the members of column from the forward dictionary
   * cache, this method will be basically used in row level filter resolver.
   *
   * @param tableIdentifier
   * @param expression
   * @param columnExpression
   * @param isIncludeFilter
   * @return DimColumnFilterInfo
   * @throws FilterUnsupportedException
   * @throws IOException
   */
public static DimColumnFilterInfo getFilterListForAllValues(AbsoluteTableIdentifier tableIdentifier, Expression expression, final ColumnExpression columnExpression, boolean isIncludeFilter) throws IOException, FilterUnsupportedException {
    Dictionary forwardDictionary = null;
    List<String> evaluateResultListFinal = new ArrayList<String>(20);
    DictionaryChunksWrapper dictionaryWrapper = null;
    try {
        forwardDictionary = getForwardDictionaryCache(tableIdentifier, columnExpression.getDimension());
        dictionaryWrapper = forwardDictionary.getDictionaryChunks();
        while (dictionaryWrapper.hasNext()) {
            byte[] columnVal = dictionaryWrapper.next();
            try {
                RowIntf row = new RowImpl();
                String stringValue = new String(columnVal, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
                if (stringValue.equals(CarbonCommonConstants.MEMBER_DEFAULT_VAL)) {
                    stringValue = null;
                }
                row.setValues(new Object[] { DataTypeUtil.getDataBasedOnDataType(stringValue, columnExpression.getCarbonColumn().getDataType()) });
                Boolean rslt = expression.evaluate(row).getBoolean();
                if (null != rslt && rslt == isIncludeFilter) {
                    if (null == stringValue) {
                        evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
                    } else {
                        evaluateResultListFinal.add(stringValue);
                    }
                }
            } catch (FilterIllegalMemberException e) {
                LOGGER.debug(e.getMessage());
            }
        }
        return getFilterValues(columnExpression, evaluateResultListFinal, forwardDictionary, isIncludeFilter);
    } finally {
        CarbonUtil.clearDictionaryCache(forwardDictionary);
    }
}
Also used : Dictionary(org.apache.carbondata.core.cache.dictionary.Dictionary) ForwardDictionary(org.apache.carbondata.core.cache.dictionary.ForwardDictionary) RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ArrayList(java.util.ArrayList) DictionaryChunksWrapper(org.apache.carbondata.core.cache.dictionary.DictionaryChunksWrapper) RowIntf(org.apache.carbondata.core.scan.filter.intf.RowIntf) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Aggregations

FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)15 ArrayList (java.util.ArrayList)7 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)6 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)5 DimColumnFilterInfo (org.apache.carbondata.core.scan.filter.DimColumnFilterInfo)5 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)3 RowIntf (org.apache.carbondata.core.scan.filter.intf.RowIntf)3 Timestamp (java.sql.Timestamp)2 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)2 BitSet (java.util.BitSet)1 Comparator (java.util.Comparator)1 Dictionary (org.apache.carbondata.core.cache.dictionary.Dictionary)1 DictionaryChunksWrapper (org.apache.carbondata.core.cache.dictionary.DictionaryChunksWrapper)1 ForwardDictionary (org.apache.carbondata.core.cache.dictionary.ForwardDictionary)1 DirectDictionaryGenerator (org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryGenerator)1 DataType (org.apache.carbondata.core.metadata.datatype.DataType)1 EqualToExpression (org.apache.carbondata.core.scan.expression.conditional.EqualToExpression)1