Search in sources :

Example 1 with ForwardDictionary

use of org.apache.carbondata.core.cache.dictionary.ForwardDictionary 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 ColumnFilterInfo
 * @throws FilterUnsupportedException
 * @throws IOException
 */
public static ColumnFilterInfo getFilterListForAllValues(AbsoluteTableIdentifier tableIdentifier, Expression expression, final ColumnExpression columnExpression, boolean isIncludeFilter, TableProvider tableProvider, boolean isExprEvalReqd) throws FilterUnsupportedException, IOException {
    Dictionary forwardDictionary = null;
    List<Integer> surrogates = new ArrayList<Integer>(20);
    try {
        forwardDictionary = getForwardDictionaryCache(tableIdentifier, columnExpression.getDimension(), tableProvider);
        if (isExprEvalReqd && !isIncludeFilter) {
            surrogates.add(CarbonCommonConstants.DICT_VALUE_NULL);
        }
        prepareIncludeFilterMembers(expression, columnExpression, isIncludeFilter, forwardDictionary, surrogates);
        ColumnFilterInfo filterInfo = getFilterValues(forwardDictionary, isIncludeFilter, surrogates);
        if (filterInfo.isOptimized()) {
            return getDimColumnFilterInfoAfterApplyingCBO(forwardDictionary, filterInfo);
        }
        return filterInfo;
    } finally {
        CarbonUtil.clearDictionaryCache(forwardDictionary);
    }
}
Also used : Dictionary(org.apache.carbondata.core.cache.dictionary.Dictionary) ForwardDictionary(org.apache.carbondata.core.cache.dictionary.ForwardDictionary) ArrayList(java.util.ArrayList)

Example 2 with ForwardDictionary

use of org.apache.carbondata.core.cache.dictionary.ForwardDictionary in project carbondata by apache.

the class FilterUtil method getFilterValues.

/**
 * Method will prepare the  dimfilterinfo instance by resolving the filter
 * expression value to its respective surrogates.
 *
 * @param tableIdentifier
 * @param columnExpression
 * @param evaluateResultList
 * @param isIncludeFilter
 * @return
 * @throws QueryExecutionException
 */
public static ColumnFilterInfo getFilterValues(AbsoluteTableIdentifier tableIdentifier, ColumnExpression columnExpression, List<String> evaluateResultList, boolean isIncludeFilter, TableProvider tableProvider) throws QueryExecutionException, FilterUnsupportedException, IOException {
    Dictionary forwardDictionary = null;
    ColumnFilterInfo filterInfo = null;
    List<Integer> surrogates = new ArrayList<Integer>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    try {
        // Reading the dictionary value from cache.
        forwardDictionary = getForwardDictionaryCache(tableIdentifier, columnExpression.getDimension(), tableProvider);
        sortFilterModelMembers(columnExpression, evaluateResultList);
        getDictionaryValue(evaluateResultList, forwardDictionary, surrogates);
        filterInfo = getFilterValues(forwardDictionary, isIncludeFilter, surrogates);
        if (filterInfo.isOptimized()) {
            return getDimColumnFilterInfoAfterApplyingCBO(forwardDictionary, filterInfo);
        }
    } finally {
        CarbonUtil.clearDictionaryCache(forwardDictionary);
    }
    return filterInfo;
}
Also used : Dictionary(org.apache.carbondata.core.cache.dictionary.Dictionary) ForwardDictionary(org.apache.carbondata.core.cache.dictionary.ForwardDictionary) ArrayList(java.util.ArrayList)

Example 3 with ForwardDictionary

use of org.apache.carbondata.core.cache.dictionary.ForwardDictionary 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)

Example 4 with ForwardDictionary

use of org.apache.carbondata.core.cache.dictionary.ForwardDictionary in project carbondata by apache.

the class PrimitiveQueryTypeTest method setUp.

@BeforeClass
public static void setUp() {
    String name = "test";
    String parentName = "testParent";
    int blockIndex = 1;
    int keySize = 1;
    boolean isDirectDictionary = true;
    primitiveQueryType = new PrimitiveQueryType(name, parentName, blockIndex, DataTypes.STRING, keySize, dictionary, isDirectDictionary);
    primitiveQueryTypeForInt = new PrimitiveQueryType(name, parentName, blockIndex, DataTypes.INT, keySize, dictionary, isDirectDictionary);
    primitiveQueryTypeForDouble = new PrimitiveQueryType(name, parentName, blockIndex, DataTypes.DOUBLE, keySize, dictionary, isDirectDictionary);
    primitiveQueryTypeForLong = new PrimitiveQueryType(name, parentName, blockIndex, DataTypes.LONG, keySize, dictionary, isDirectDictionary);
    primitiveQueryTypeForBoolean = new PrimitiveQueryType(name, parentName, blockIndex, DataTypes.BOOLEAN, keySize, dictionary, isDirectDictionary);
    primitiveQueryTypeForTimeStamp = new PrimitiveQueryType(name, parentName, blockIndex, DataTypes.TIMESTAMP, keySize, dictionary, isDirectDictionary);
    ColumnDictionaryInfo columnDictionaryInfo = new ColumnDictionaryInfo(DataTypes.STRING);
    ForwardDictionary forwardDictionary = new ForwardDictionary(columnDictionaryInfo);
    primitiveQueryTypeForTimeStampForIsDictionaryFalse = new PrimitiveQueryType(name, parentName, blockIndex, DataTypes.TIMESTAMP, keySize, forwardDictionary, false);
}
Also used : ForwardDictionary(org.apache.carbondata.core.cache.dictionary.ForwardDictionary) ColumnDictionaryInfo(org.apache.carbondata.core.cache.dictionary.ColumnDictionaryInfo) BeforeClass(org.junit.BeforeClass)

Aggregations

ForwardDictionary (org.apache.carbondata.core.cache.dictionary.ForwardDictionary)4 ArrayList (java.util.ArrayList)3 Dictionary (org.apache.carbondata.core.cache.dictionary.Dictionary)3 ColumnDictionaryInfo (org.apache.carbondata.core.cache.dictionary.ColumnDictionaryInfo)1 DictionaryChunksWrapper (org.apache.carbondata.core.cache.dictionary.DictionaryChunksWrapper)1 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)1 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)1 RowIntf (org.apache.carbondata.core.scan.filter.intf.RowIntf)1 BeforeClass (org.junit.BeforeClass)1