Search in sources :

Example 6 with MultiDimKeyVarLengthGenerator

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

the class BTreeBlockFinderTest method getFileFooterListWithOnlyDictionaryKey.

private List<DataFileFooter> getFileFooterListWithOnlyDictionaryKey() {
    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(1 + 4);
            buffer.rewind();
            buffer.put((byte) 1);
            buffer.putInt(i);
            buffer.array();
            byte[] noDictionaryStartKey = buffer.array();
            ByteBuffer buffer1 = ByteBuffer.allocate(1 + 4);
            buffer1.rewind();
            buffer1.put((byte) 1);
            buffer1.putInt(i + 10);
            buffer1.array();
            byte[] noDictionaryEndKey = buffer1.array();
            DataFileFooter footer = getFileFooterWithOnlyDictionaryKey(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 7 with MultiDimKeyVarLengthGenerator

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

the class FilterUtilTest method testGetMaskKey.

@Test
public void testGetMaskKey() {
    int surrogate = 1;
    int[] keys = new int[] { 1, 2 };
    MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator = new MultiDimKeyVarLengthGenerator(keys);
    int ordinal = 1;
    int keyOrdinal = 1;
    int columnGroupOrdinal = 1;
    int complexTypeOrdinal = 1;
    ColumnSchema columnSchema = new ColumnSchema();
    columnSchema.setColumnar(true);
    columnSchema.setColumnName("IMEI");
    columnSchema.setColumnUniqueId(UUID.randomUUID().toString());
    columnSchema.setDataType(DataTypes.STRING);
    columnSchema.setDimensionColumn(true);
    CarbonDimension carbonDimension = new CarbonDimension(columnSchema, ordinal, keyOrdinal, columnGroupOrdinal, complexTypeOrdinal);
    byte[] expectedResult = new byte[] { 1 };
    byte[] actualResult = FilterUtil.getMaskKey(surrogate, carbonDimension, multiDimKeyVarLengthGenerator);
    assertArrayEquals(expectedResult, actualResult);
}
Also used : MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Example 8 with MultiDimKeyVarLengthGenerator

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

the class ColumnGroupDimensionDataChunkTest method setup.

@BeforeClass
public static void setup() {
    int[] bitLength = CarbonUtil.getDimensionBitLength(new int[] { 10, 10, 10 }, new int[] { 3 });
    // create a key generator
    keyGenerator = new MultiDimKeyVarLengthGenerator(bitLength);
    byte[] data = new byte[keyGenerator.getKeySizeInBytes() * 3];
    int position = 0;
    for (int i = 1; i <= 3; i++) {
        try {
            System.arraycopy(keyGenerator.generateKey(new int[] { i, i, i }), 0, data, position, keyGenerator.getKeySizeInBytes());
        } catch (KeyGenException e) {
            assertTrue(false);
        }
        position += keyGenerator.getKeySizeInBytes();
    }
    columnGroupDimensionDataChunk = new ColumnGroupDimensionColumnPage(data, keyGenerator.getKeySizeInBytes(), 3);
}
Also used : MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) KeyGenException(org.apache.carbondata.core.keygenerator.KeyGenException) BeforeClass(org.junit.BeforeClass)

Example 9 with MultiDimKeyVarLengthGenerator

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

the class FilterUtilTest method testCreateIndexKeyFromResolvedFilterVal.

@Test
public void testCreateIndexKeyFromResolvedFilterVal() throws Exception {
    long[] startOrEndKey = new long[] { 0, 10 };
    byte[] startOrEndKeyForNoDictDimension = { 1, 2 };
    int[] keys = new int[] { 1, 2 };
    MultiDimKeyVarLengthGenerator multiDimKeyVarLengthGenerator = new MultiDimKeyVarLengthGenerator(keys);
    assertTrue(FilterUtil.createIndexKeyFromResolvedFilterVal(startOrEndKey, multiDimKeyVarLengthGenerator, startOrEndKeyForNoDictDimension) != null);
}
Also used : MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Example 10 with MultiDimKeyVarLengthGenerator

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

the class SegmentProperties method fillKeyGeneratorDetails.

/**
 * Below method will fill the key generator detail of both the type of key
 * generator. This will be required for during both query execution and data
 * loading.
 */
private void fillKeyGeneratorDetails() {
    // create a dimension partitioner list
    // this list will contain information about how dimension value are
    // stored
    // it is stored in group or individually
    List<Integer> dimensionPartitionList = new ArrayList<Integer>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    List<Boolean> isDictionaryColumn = new ArrayList<Boolean>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    int prvcolumnGroupId = -1;
    int counter = 0;
    while (counter < dimensions.size()) {
        CarbonDimension carbonDimension = dimensions.get(counter);
        // if dimension is not a part of mdkey then no need to add
        if (!carbonDimension.getEncoder().contains(Encoding.DICTIONARY)) {
            isDictionaryColumn.add(false);
            counter++;
            continue;
        }
        // so add one
        if (carbonDimension.isColumnar()) {
            dimensionPartitionList.add(1);
            isDictionaryColumn.add(true);
        }
        // group
        if (!carbonDimension.isColumnar() && carbonDimension.columnGroupId() == prvcolumnGroupId) {
            // incrementing the previous value of the list as it is in same column group
            dimensionPartitionList.set(dimensionPartitionList.size() - 1, dimensionPartitionList.get(dimensionPartitionList.size() - 1) + 1);
        } else if (!carbonDimension.isColumnar()) {
            dimensionPartitionList.add(1);
            isDictionaryColumn.add(true);
        }
        prvcolumnGroupId = carbonDimension.columnGroupId();
        counter++;
    }
    // get the partitioner
    dimensionPartitions = ArrayUtils.toPrimitive(dimensionPartitionList.toArray(new Integer[dimensionPartitionList.size()]));
    // get the bit length of each column
    int[] bitLength = CarbonUtil.getDimensionBitLength(dimColumnsCardinality, dimensionPartitions);
    // create a key generator
    this.dimensionKeyGenerator = new MultiDimKeyVarLengthGenerator(bitLength);
    if (this.getNumberOfDictSortColumns() == bitLength.length) {
        this.sortColumnsGenerator = this.dimensionKeyGenerator;
    } else {
        int numberOfDictSortColumns = this.getNumberOfDictSortColumns();
        int[] sortColumnBitLength = new int[numberOfDictSortColumns];
        System.arraycopy(bitLength, 0, sortColumnBitLength, 0, numberOfDictSortColumns);
        this.sortColumnsGenerator = new MultiDimKeyVarLengthGenerator(sortColumnBitLength);
    }
    this.fixedLengthKeySplitter = new MultiDimKeyVarLengthVariableSplitGenerator(bitLength, dimensionPartitions);
    // get the size of each value in file block
    int[] dictionaryDimColumnValueSize = fixedLengthKeySplitter.getBlockKeySize();
    int index = -1;
    this.eachDimColumnValueSize = new int[isDictionaryColumn.size()];
    for (int i = 0; i < eachDimColumnValueSize.length; i++) {
        if (!isDictionaryColumn.get(i)) {
            eachDimColumnValueSize[i] = -1;
            continue;
        }
        eachDimColumnValueSize[i] = dictionaryDimColumnValueSize[++index];
    }
    if (complexDimensions.size() > 0) {
        int[] complexDimensionPartition = new int[complexDimColumnCardinality.length];
        // as complex dimension will be stored in column format add one
        Arrays.fill(complexDimensionPartition, 1);
        bitLength = CarbonUtil.getDimensionBitLength(complexDimColumnCardinality, complexDimensionPartition);
        for (int i = 0; i < bitLength.length; i++) {
            if (complexDimColumnCardinality[i] == 0) {
                bitLength[i] = 64;
            }
        }
        ColumnarSplitter keySplitter = new MultiDimKeyVarLengthVariableSplitGenerator(bitLength, complexDimensionPartition);
        eachComplexDimColumnValueSize = keySplitter.getBlockKeySize();
    } else {
        eachComplexDimColumnValueSize = new int[0];
    }
}
Also used : MultiDimKeyVarLengthVariableSplitGenerator(org.apache.carbondata.core.keygenerator.columnar.impl.MultiDimKeyVarLengthVariableSplitGenerator) ColumnarSplitter(org.apache.carbondata.core.keygenerator.columnar.ColumnarSplitter) MultiDimKeyVarLengthGenerator(org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator) ArrayList(java.util.ArrayList) 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