Search in sources :

Example 11 with SegmentProperties

use of org.apache.carbondata.core.datastore.block.SegmentProperties in project carbondata by apache.

the class FilterUtilTest method testPrepareDefaultStartIndexKey.

@Test
public void testPrepareDefaultStartIndexKey() throws KeyGenException {
    List<ColumnSchema> columnsInTable = new ArrayList<>();
    columnsInTable.add(columnSchema);
    int[] columnCardinality = new int[] { 1, 2 };
    new MockUp<ColumnSchema>() {

        @Mock
        public List<Encoding> getEncodingList() {
            List<Encoding> encodingList = new ArrayList<>();
            encodingList.add(Encoding.DICTIONARY);
            return encodingList;
        }
    };
    SegmentProperties segmentProperties = new SegmentProperties(columnsInTable, columnCardinality);
    assertTrue(FilterUtil.prepareDefaultStartIndexKey(segmentProperties) instanceof IndexKey);
}
Also used : IndexKey(org.apache.carbondata.core.datastore.IndexKey) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) MockUp(mockit.MockUp) Encoding(org.apache.carbondata.core.metadata.encoder.Encoding) SegmentProperties(org.apache.carbondata.core.datastore.block.SegmentProperties) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Example 12 with SegmentProperties

use of org.apache.carbondata.core.datastore.block.SegmentProperties 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 = tableBlockExecutionInfos.getDataBlock().getSegmentProperties();
    QueryDimension[] queryDimensions = tableBlockExecutionInfos.getActualQueryDimensions();
    List<Integer> updatedColumnCardinality = new ArrayList<>(queryDimensions.length);
    List<Integer> updatedDimensionPartitioner = new ArrayList<>(queryDimensions.length);
    int[] dictionaryColumnBlockIndex = tableBlockExecutionInfos.getDictionaryColumnBlockIndex();
    int dimCounterInCurrentBlock = 0;
    for (int i = 0; i < queryDimensions.length; i++) {
        if (queryDimensions[i].getDimension().hasEncoding(Encoding.DICTIONARY)) {
            if (tableBlockExecutionInfos.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) QueryDimension(org.apache.carbondata.core.scan.model.QueryDimension) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 13 with SegmentProperties

use of org.apache.carbondata.core.datastore.block.SegmentProperties 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 = tableBlockExecutionInfos.getDataBlock().getSegmentProperties();
    int[] dictionaryColumnBlockIndex = tableBlockExecutionInfos.getDictionaryColumnBlockIndex();
    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 14 with SegmentProperties

use of org.apache.carbondata.core.datastore.block.SegmentProperties in project carbondata by apache.

the class CarbonFooterWriterTest method testWriteFactMetadata.

/**
   * test writing fact metadata.
   */
@Test
public void testWriteFactMetadata() throws IOException {
    deleteFile();
    createFile();
    CarbonFooterWriter writer = new CarbonFooterWriter(filePath);
    List<BlockletInfoColumnar> infoColumnars = getBlockletInfoColumnars();
    int[] cardinalities = new int[] { 2, 4, 5, 7, 9, 10 };
    List<ColumnSchema> columnSchema = Arrays.asList(new ColumnSchema[] { getDimensionColumn("IMEI1"), getDimensionColumn("IMEI2"), getDimensionColumn("IMEI3"), getDimensionColumn("IMEI4"), getDimensionColumn("IMEI5"), getDimensionColumn("IMEI6") });
    List<org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema> wrapperColumnSchema = Arrays.asList(new org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema[] { getWrapperDimensionColumn("IMEI1"), getWrapperDimensionColumn("IMEI2"), getWrapperDimensionColumn("IMEI3"), getWrapperDimensionColumn("IMEI4"), getWrapperDimensionColumn("IMEI5"), getWrapperDimensionColumn("IMEI6") });
    int[] colCardinality = CarbonUtil.getFormattedCardinality(cardinalities, wrapperColumnSchema);
    SegmentProperties segmentProperties = new SegmentProperties(wrapperColumnSchema, colCardinality);
    writer.writeFooter(CarbonMetadataUtil.convertFileFooter(infoColumnars, 6, cardinalities, columnSchema, segmentProperties), 0);
    CarbonFooterReader metaDataReader = new CarbonFooterReader(filePath, 0);
    assertTrue(metaDataReader.readFooter() != null);
}
Also used : BlockletInfoColumnar(org.apache.carbondata.core.metadata.BlockletInfoColumnar) ColumnSchema(org.apache.carbondata.format.ColumnSchema) SegmentProperties(org.apache.carbondata.core.datastore.block.SegmentProperties) CarbonFooterReader(org.apache.carbondata.core.reader.CarbonFooterReader) Test(org.junit.Test)

Aggregations

SegmentProperties (org.apache.carbondata.core.datastore.block.SegmentProperties)14 ArrayList (java.util.ArrayList)8 IndexKey (org.apache.carbondata.core.datastore.IndexKey)5 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 MockUp (mockit.MockUp)3 KeyGenException (org.apache.carbondata.core.keygenerator.KeyGenException)3 BlockletInfoColumnar (org.apache.carbondata.core.metadata.BlockletInfoColumnar)3 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)3 ColumnSchema (org.apache.carbondata.format.ColumnSchema)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)2 DataRefNode (org.apache.carbondata.core.datastore.DataRefNode)2 DataRefNodeFinder (org.apache.carbondata.core.datastore.DataRefNodeFinder)2 BTreeDataRefNodeFinder (org.apache.carbondata.core.datastore.impl.btree.BTreeDataRefNodeFinder)2 MultiDimKeyVarLengthGenerator (org.apache.carbondata.core.keygenerator.mdkey.MultiDimKeyVarLengthGenerator)2 DataFileFooter (org.apache.carbondata.core.metadata.blocklet.DataFileFooter)2 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)2