Search in sources :

Example 11 with MultiDimKeyVarLengthGenerator

use of org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator in project carbondata by apache.

the class BTreeBlockFinderTest method getFileFooterListWithOnlyNoDictionaryKey.

private List<DataFileFooter> getFileFooterListWithOnlyNoDictionaryKey() {
    List<DataFileFooter> list = new ArrayList<DataFileFooter>();
    try {
        int[] dimensionBitLength = CarbonUtil.getDimensionBitLength(new int[] { 10000, 10000 }, new int[] { 1, 1 });
        KeyGenerator multiDimKeyVarLengthGenerator = new MultiDimKeyVarLengthGenerator(dimensionBitLength);
        int i = 1;
        while (i < 1001) {
            byte[] startKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i, i });
            byte[] endKey = multiDimKeyVarLengthGenerator.generateKey(new int[] { i + 10, i + 10 });
            ByteBuffer buffer = ByteBuffer.allocate(2 + 4);
            buffer.rewind();
            buffer.putShort((short) 1);
            buffer.putInt(i);
            buffer.array();
            byte[] noDictionaryStartKey = buffer.array();
            ByteBuffer buffer1 = ByteBuffer.allocate(2 + 4);
            buffer1.rewind();
            buffer1.putShort((short) 2);
            buffer1.putInt(i + 10);
            buffer1.array();
            byte[] noDictionaryEndKey = buffer1.array();
            DataFileFooter footer = getFileMatadataWithOnlyNoDictionaryKey(startKey, endKey, noDictionaryStartKey, noDictionaryEndKey);
            list.add(footer);
            i = i + 10;
        }
    } catch (Exception e) {
        LOGGER.error(e);
    }
    return list;
}
Also used : MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) DataFileFooter(org.apache.carbondata.core.metadata.blocklet.DataFileFooter) ArrayList(java.util.ArrayList) KeyGenerator(org.apache.carbondata.core.keygenerator.KeyGenerator) ByteBuffer(java.nio.ByteBuffer) KeyGenException(org.apache.carbondata.core.keygenerator.KeyGenException)

Example 12 with MultiDimKeyVarLengthGenerator

use of org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator in project carbondata by apache.

the class RestructureBasedRawResultCollector method initCurrentBlockKeyGenerator.

/**
 * This method will initialize the block key generator for the current block based on the
 * dictionary columns present in the current block
 */
private void initCurrentBlockKeyGenerator() {
    SegmentProperties segmentProperties = executionInfo.getDataBlock().getSegmentProperties();
    int[] dictionaryColumnBlockIndex = executionInfo.getDictionaryColumnChunkIndex();
    int[] updatedColumnCardinality = new int[dictionaryColumnBlockIndex.length];
    int[] updatedDimensionPartitioner = new int[dictionaryColumnBlockIndex.length];
    for (int i = 0; i < dictionaryColumnBlockIndex.length; i++) {
        // get the dictionary key ordinal as column cardinality in segment properties
        // will only be for dictionary encoded columns
        CarbonDimension currentBlockDimension = segmentProperties.getDimensions().get(dictionaryColumnBlockIndex[i]);
        updatedColumnCardinality[i] = segmentProperties.getDimColumnsCardinality()[currentBlockDimension.getKeyOrdinal()];
        updatedDimensionPartitioner[i] = segmentProperties.getDimensionPartitions()[currentBlockDimension.getKeyOrdinal()];
    }
    if (dictionaryColumnBlockIndex.length > 0) {
        int[] dimensionBitLength = CarbonUtil.getDimensionBitLength(updatedColumnCardinality, updatedDimensionPartitioner);
        updatedCurrentBlockKeyGenerator = new MultiDimKeyVarLengthGenerator(dimensionBitLength);
    }
}
Also used : MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) SegmentProperties(org.apache.carbondata.core.datastore.block.SegmentProperties) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 13 with MultiDimKeyVarLengthGenerator

use of org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator in project carbondata by apache.

the class RestructureBasedRawResultCollector method initRestructuredKeyGenerator.

/**
 * This method will create a new key generator for generating mdKey according to latest schema
 */
private void initRestructuredKeyGenerator() {
    SegmentProperties segmentProperties = executionInfo.getDataBlock().getSegmentProperties();
    ProjectionDimension[] queryDimensions = executionInfo.getActualQueryDimensions();
    List<Integer> updatedColumnCardinality = new ArrayList<>(queryDimensions.length);
    List<Integer> updatedDimensionPartitioner = new ArrayList<>(queryDimensions.length);
    int[] dictionaryColumnBlockIndex = executionInfo.getDictionaryColumnChunkIndex();
    int dimCounterInCurrentBlock = 0;
    for (int i = 0; i < queryDimensions.length; i++) {
        if (queryDimensions[i].getDimension().hasEncoding(Encoding.DICTIONARY)) {
            if (executionInfo.getDimensionInfo().getDimensionExists()[i]) {
                // get the dictionary key ordinal as column cardinality in segment properties
                // will only be for dictionary encoded columns
                CarbonDimension currentBlockDimension = segmentProperties.getDimensions().get(dictionaryColumnBlockIndex[dimCounterInCurrentBlock]);
                updatedColumnCardinality.add(segmentProperties.getDimColumnsCardinality()[currentBlockDimension.getKeyOrdinal()]);
                updatedDimensionPartitioner.add(segmentProperties.getDimensionPartitions()[currentBlockDimension.getKeyOrdinal()]);
                dimCounterInCurrentBlock++;
            } else {
                // partitioner index will be 1 every column will be in columnar format
                updatedDimensionPartitioner.add(1);
                // for direct dictionary 4 bytes need to be allocated else 1
                if (queryDimensions[i].getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                    updatedColumnCardinality.add(Integer.MAX_VALUE);
                } else {
                    // cardinality will be 2 will user has provided a default value
                    byte[] defaultValue = queryDimensions[i].getDimension().getDefaultValue();
                    if (null != defaultValue) {
                        updatedColumnCardinality.add(CarbonCommonConstants.DICTIONARY_DEFAULT_CARDINALITY + 1);
                    } else {
                        updatedColumnCardinality.add(CarbonCommonConstants.DICTIONARY_DEFAULT_CARDINALITY);
                    }
                }
            }
        }
    }
    if (!updatedColumnCardinality.isEmpty()) {
        int[] latestColumnCardinality = ArrayUtils.toPrimitive(updatedColumnCardinality.toArray(new Integer[updatedColumnCardinality.size()]));
        int[] latestColumnPartitioner = ArrayUtils.toPrimitive(updatedDimensionPartitioner.toArray(new Integer[updatedDimensionPartitioner.size()]));
        int[] dimensionBitLength = CarbonUtil.getDimensionBitLength(latestColumnCardinality, latestColumnPartitioner);
        restructuredKeyGenerator = new MultiDimKeyVarLengthGenerator(dimensionBitLength);
    }
}
Also used : MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) ArrayList(java.util.ArrayList) SegmentProperties(org.apache.carbondata.core.datastore.block.SegmentProperties) ProjectionDimension(org.apache.carbondata.core.scan.model.ProjectionDimension) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Aggregations

MultiDimKeyVarLengthGenerator (org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator)13 KeyGenerator (org.apache.carbondata.core.keygenerator.KeyGenerator)7 ArrayList (java.util.ArrayList)6 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)6 Test (org.junit.Test)5 KeyGenException (org.apache.carbondata.core.keygenerator.KeyGenException)4 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)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 IndexKey (org.apache.carbondata.core.datastore.IndexKey)3 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)2 SegmentProperties (org.apache.carbondata.core.datastore.block.SegmentProperties)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 ColumnarSplitter (org.apache.carbondata.core.keygenerator.columnar.ColumnarSplitter)1 MultiDimKeyVarLengthVariableSplitGenerator (org.apache.carbondata.core.keygenerator.columnar.impl.MultiDimKeyVarLengthVariableSplitGenerator)1