Search in sources :

Example 6 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class FilterUtil method getExcludeFilterExecuter.

/**
   * It gives filter executer based on columnar or column group
   *
   * @param dimColResolvedFilterInfo
   * @param segmentProperties
   * @return
   */
private static FilterExecuter getExcludeFilterExecuter(DimColumnResolvedFilterInfo dimColResolvedFilterInfo, SegmentProperties segmentProperties) {
    if (dimColResolvedFilterInfo.getDimension().isColumnar()) {
        CarbonDimension dimensionFromCurrentBlock = segmentProperties.getDimensionFromCurrentBlock(dimColResolvedFilterInfo.getDimension());
        if (null != dimensionFromCurrentBlock) {
            // update dimension and column index according to the dimension position in current block
            DimColumnResolvedFilterInfo dimColResolvedFilterInfoCopyObject = dimColResolvedFilterInfo.getCopyObject();
            dimColResolvedFilterInfoCopyObject.setDimension(dimensionFromCurrentBlock);
            dimColResolvedFilterInfoCopyObject.setColumnIndex(dimensionFromCurrentBlock.getOrdinal());
            return new ExcludeFilterExecuterImpl(dimColResolvedFilterInfoCopyObject, segmentProperties);
        } else {
            return new RestructureExcludeFilterExecutorImpl(dimColResolvedFilterInfo, segmentProperties);
        }
    } else {
        return new ExcludeColGroupFilterExecuterImpl(dimColResolvedFilterInfo, segmentProperties);
    }
}
Also used : DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) ExcludeColGroupFilterExecuterImpl(org.apache.carbondata.core.scan.filter.executer.ExcludeColGroupFilterExecuterImpl) ExcludeFilterExecuterImpl(org.apache.carbondata.core.scan.filter.executer.ExcludeFilterExecuterImpl) RestructureExcludeFilterExecutorImpl(org.apache.carbondata.core.scan.filter.executer.RestructureExcludeFilterExecutorImpl) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 7 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class FilterUtil method getEndKeyForNoDictionaryDimension.

/**
   * Algorithm for getting the end key for a filter
   * step 1: Iterate through each dimension and verify whether its not an exclude filter.
   * step 2: Initialize end key with the last filter member value present in each filter model
   * for the respective dimensions.(Already filter models are sorted)
   * step 3: since its a no dictionary end key there will only actual value so compare
   * the last filter model value with respect to the dimension data type.
   * step 4: The highest value will be considered as the end key of dimension by comparing all
   * its filter model.
   * step 5: create a byte array of end key which comprises of highest filter member value of
   * all dimension and the indexes which will help to read the respective filter value.
   *
   * @param dimColResolvedFilterInfo
   * @param setOfEndKeyByteArray
   * @return end key array
   */
public static void getEndKeyForNoDictionaryDimension(DimColumnResolvedFilterInfo dimColResolvedFilterInfo, SegmentProperties segmentProperties, SortedMap<Integer, byte[]> setOfEndKeyByteArray) {
    Map<CarbonDimension, List<DimColumnFilterInfo>> dimensionFilter = dimColResolvedFilterInfo.getDimensionResolvedFilterInstance();
    // step 1
    for (Map.Entry<CarbonDimension, List<DimColumnFilterInfo>> entry : dimensionFilter.entrySet()) {
        if (!entry.getKey().hasEncoding(Encoding.DICTIONARY)) {
            List<DimColumnFilterInfo> listOfDimColFilterInfo = entry.getValue();
            if (null == listOfDimColFilterInfo) {
                continue;
            }
            boolean isExcludePresent = false;
            for (DimColumnFilterInfo info : listOfDimColFilterInfo) {
                if (!info.isIncludeFilter()) {
                    isExcludePresent = true;
                }
            }
            if (isExcludePresent) {
                continue;
            }
            // in case of restructure scenarios it can happen that the filter dimension is not
            // present in the current block. In those cases no need to determine the key
            CarbonDimension dimensionFromCurrentBlock = CarbonUtil.getDimensionFromCurrentBlock(segmentProperties.getDimensions(), entry.getKey());
            if (null == dimensionFromCurrentBlock) {
                continue;
            }
            // step 2
            byte[] noDictionaryEndKey = listOfDimColFilterInfo.get(0).getNoDictionaryFilterValuesList().get(listOfDimColFilterInfo.get(0).getNoDictionaryFilterValuesList().size() - 1);
            if (setOfEndKeyByteArray.isEmpty()) {
                setOfEndKeyByteArray.put(dimensionFromCurrentBlock.getOrdinal(), noDictionaryEndKey);
            } else if (null == setOfEndKeyByteArray.get(dimensionFromCurrentBlock.getOrdinal())) {
                setOfEndKeyByteArray.put(dimensionFromCurrentBlock.getOrdinal(), noDictionaryEndKey);
            } else if (ByteUtil.UnsafeComparer.INSTANCE.compareTo(setOfEndKeyByteArray.get(dimensionFromCurrentBlock.getOrdinal()), noDictionaryEndKey) < 0) {
                setOfEndKeyByteArray.put(dimensionFromCurrentBlock.getOrdinal(), noDictionaryEndKey);
            }
        }
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 8 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class RangeValueFilterExecuterImpl method ifDefaultValueMatchesFilter.

/**
   * This method will check whether default value is present in the given filter values
   */
private void ifDefaultValueMatchesFilter() {
    isDefaultValuePresentInFilter = false;
    if (!this.isDimensionPresentInCurrentBlock) {
        CarbonDimension dimension = this.dimColEvaluatorInfo.getDimension();
        byte[] defaultValue = dimension.getDefaultValue();
        if (null != defaultValue) {
            int maxCompare = ByteUtil.UnsafeComparer.INSTANCE.compareTo(defaultValue, filterRangesValues[0]);
            int minCompare = ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterRangesValues[1], defaultValue);
            if (((greaterThanExp && maxCompare > 0) || (greaterThanEqualExp && maxCompare >= 0)) && ((lessThanExp && minCompare > 0) || (lessThanEqualExp && minCompare >= 0))) {
                isDefaultValuePresentInFilter = true;
            }
        }
    }
}
Also used : CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 9 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class FilterUtil method getEndKeyWithFilter.

private static void getEndKeyWithFilter(Map<CarbonDimension, List<DimColumnFilterInfo>> dimensionFilter, SegmentProperties segmentProperties, long[] endKey, List<long[]> endKeyList) {
    for (Map.Entry<CarbonDimension, List<DimColumnFilterInfo>> entry : dimensionFilter.entrySet()) {
        List<DimColumnFilterInfo> values = entry.getValue();
        if (null == values || !entry.getKey().hasEncoding(Encoding.DICTIONARY)) {
            continue;
        }
        boolean isExcludeFilterPresent = false;
        for (DimColumnFilterInfo info : values) {
            if (!info.isIncludeFilter()) {
                isExcludeFilterPresent = true;
            }
        }
        if (isExcludeFilterPresent) {
            continue;
        }
        // search the query dimension in current block dimensions. If the dimension is not found
        // that means the key cannot be included in start key formation.
        // Applicable for restructure scenarios
        CarbonDimension dimensionFromCurrentBlock = segmentProperties.getDimensionFromCurrentBlock(entry.getKey());
        if (null == dimensionFromCurrentBlock) {
            continue;
        }
        int keyOrdinalOfDimensionFromCurrentBlock = dimensionFromCurrentBlock.getKeyOrdinal();
        for (DimColumnFilterInfo info : values) {
            if (keyOrdinalOfDimensionFromCurrentBlock < endKey.length) {
                if (endKey[keyOrdinalOfDimensionFromCurrentBlock] > info.getFilterList().get(info.getFilterList().size() - 1)) {
                    endKey[keyOrdinalOfDimensionFromCurrentBlock] = info.getFilterList().get(info.getFilterList().size() - 1);
                }
            }
        }
        long[] newEndKey = new long[endKey.length];
        System.arraycopy(endKey, 0, newEndKey, 0, endKey.length);
        endKeyList.add(newEndKey);
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 10 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class ServerDictionaryGenerator method initializeGeneratorForTable.

public void initializeGeneratorForTable(DictionaryMessage key) {
    CarbonMetadata metadata = CarbonMetadata.getInstance();
    CarbonTable carbonTable = metadata.getCarbonTable(key.getTableUniqueName());
    CarbonDimension dimension = carbonTable.getPrimitiveDimensionByName(key.getTableUniqueName(), key.getColumnName());
    // initialize TableDictionaryGenerator first
    if (tableMap.get(key.getTableUniqueName()) == null) {
        tableMap.put(key.getTableUniqueName(), new TableDictionaryGenerator(dimension));
    } else {
        tableMap.get(key.getTableUniqueName()).updateGenerator(dimension);
    }
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) CarbonMetadata(org.apache.carbondata.core.metadata.CarbonMetadata) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Aggregations

CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)85 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)31 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)23 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)15 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)13 QueryDimension (org.apache.carbondata.core.scan.model.QueryDimension)9 CarbonMetadata (org.apache.carbondata.core.metadata.CarbonMetadata)7 HashSet (java.util.HashSet)6 List (java.util.List)5 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)5 Expression (org.apache.carbondata.core.scan.expression.Expression)5 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)5 FilterOptimizer (org.apache.carbondata.core.scan.filter.intf.FilterOptimizer)5 FilterOptimizerBasic (org.apache.carbondata.core.scan.filter.intf.FilterOptimizerBasic)5 RangeFilterOptmizer (org.apache.carbondata.core.scan.filter.optimizer.RangeFilterOptmizer)5 Map (java.util.Map)4 SortedMap (java.util.SortedMap)4 TreeMap (java.util.TreeMap)4 TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)4