Search in sources :

Example 16 with KeyGenerator

use of org.apache.carbondata.core.keygenerator.KeyGenerator in project carbondata by apache.

the class FilterUtil method getKeyArray.

/**
   * Below method will be used to covert the filter surrogate keys
   * to mdkey
   *
   * @param dimColumnFilterInfo
   * @param carbonDimension
   * @param segmentProperties
   * @return
   */
public static byte[][] getKeyArray(DimColumnFilterInfo dimColumnFilterInfo, CarbonDimension carbonDimension, SegmentProperties segmentProperties) {
    if (!carbonDimension.hasEncoding(Encoding.DICTIONARY)) {
        return dimColumnFilterInfo.getNoDictionaryFilterValuesList().toArray((new byte[dimColumnFilterInfo.getNoDictionaryFilterValuesList().size()][]));
    }
    KeyGenerator blockLevelKeyGenerator = segmentProperties.getDimensionKeyGenerator();
    int[] dimColumnsCardinality = segmentProperties.getDimColumnsCardinality();
    int[] keys = new int[blockLevelKeyGenerator.getDimCount()];
    List<byte[]> filterValuesList = new ArrayList<byte[]>(20);
    Arrays.fill(keys, 0);
    int keyOrdinalOfDimensionFromCurrentBlock = carbonDimension.getKeyOrdinal();
    if (null != dimColumnFilterInfo) {
        int[] rangesForMaskedByte = getRangesForMaskedByte(keyOrdinalOfDimensionFromCurrentBlock, blockLevelKeyGenerator);
        for (Integer surrogate : dimColumnFilterInfo.getFilterList()) {
            try {
                if (surrogate <= dimColumnsCardinality[keyOrdinalOfDimensionFromCurrentBlock]) {
                    keys[keyOrdinalOfDimensionFromCurrentBlock] = surrogate;
                    filterValuesList.add(getMaskedKey(rangesForMaskedByte, blockLevelKeyGenerator.generateKey(keys)));
                } else {
                    break;
                }
            } catch (KeyGenException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
    return filterValuesList.toArray(new byte[filterValuesList.size()][]);
}
Also used : ArrayList(java.util.ArrayList) KeyGenException(org.apache.carbondata.core.keygenerator.KeyGenException) KeyGenerator(org.apache.carbondata.core.keygenerator.KeyGenerator)

Aggregations

KeyGenerator (org.apache.carbondata.core.keygenerator.KeyGenerator)16 ArrayList (java.util.ArrayList)10 MultiDimKeyVarLengthGenerator (org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator)7 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)6 Test (org.junit.Test)6 KeyGenException (org.apache.carbondata.core.keygenerator.KeyGenException)5 IndexKey (org.apache.carbondata.core.datastore.IndexKey)4 KeyStructureInfo (org.apache.carbondata.core.scan.executor.infos.KeyStructureInfo)4 ByteBuffer (java.nio.ByteBuffer)3 BTreeBuilderInfo (org.apache.carbondata.core.datastore.BTreeBuilderInfo)3 BtreeBuilder (org.apache.carbondata.core.datastore.BtreeBuilder)3 DataRefNode (org.apache.carbondata.core.datastore.DataRefNode)3 DataRefNodeFinder (org.apache.carbondata.core.datastore.DataRefNodeFinder)3 KeyGeneratorFactory.getKeyGenerator (org.apache.carbondata.core.keygenerator.factory.KeyGeneratorFactory.getKeyGenerator)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 SegmentProperties (org.apache.carbondata.core.datastore.block.SegmentProperties)1