Search in sources :

Example 6 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class RowLevelFilterExecuterImpl method createRow.

/**
   * Method will read the members of particular dimension block and create
   * a row instance for further processing of the filters
   *
   * @param blockChunkHolder
   * @param row
   * @param index
   * @throws IOException
   */
private void createRow(BlocksChunkHolder blockChunkHolder, RowIntf row, int pageIndex, int index) throws IOException {
    Object[] record = new Object[dimColEvaluatorInfoList.size() + msrColEvalutorInfoList.size()];
    String memberString;
    for (int i = 0; i < dimColEvaluatorInfoList.size(); i++) {
        DimColumnResolvedFilterInfo dimColumnEvaluatorInfo = dimColEvaluatorInfoList.get(i);
        // if filter dimension is not present in the current add its default value
        if (!isDimensionPresentInCurrentBlock[i]) {
            // fill default value here
            record[dimColumnEvaluatorInfo.getRowIndex()] = getDimensionDefaultValue(dimColumnEvaluatorInfo);
            continue;
        }
        if (dimColumnEvaluatorInfo.getDimension().getDataType() != DataType.ARRAY && dimColumnEvaluatorInfo.getDimension().getDataType() != DataType.STRUCT) {
            if (!dimColumnEvaluatorInfo.isDimensionExistsInCurrentSilce()) {
                record[dimColumnEvaluatorInfo.getRowIndex()] = dimColumnEvaluatorInfo.getDimension().getDefaultValue();
            }
            DimensionColumnDataChunk columnDataChunk = blockChunkHolder.getDimensionRawDataChunk()[dimensionBlocksIndex[i]].convertToDimColDataChunk(pageIndex);
            if (!dimColumnEvaluatorInfo.getDimension().hasEncoding(Encoding.DICTIONARY) && columnDataChunk instanceof VariableLengthDimensionDataChunk) {
                VariableLengthDimensionDataChunk dimensionColumnDataChunk = (VariableLengthDimensionDataChunk) columnDataChunk;
                byte[] memberBytes = dimensionColumnDataChunk.getChunkData(index);
                if (null != memberBytes) {
                    if (Arrays.equals(CarbonCommonConstants.MEMBER_DEFAULT_VAL_ARRAY, memberBytes)) {
                        memberBytes = null;
                    }
                    record[dimColumnEvaluatorInfo.getRowIndex()] = DataTypeUtil.getDataBasedOnDataTypeForNoDictionaryColumn(memberBytes, dimColumnEvaluatorInfo.getDimension().getDataType());
                } else {
                    continue;
                }
            } else {
                int dictionaryValue = readSurrogatesFromColumnBlock(blockChunkHolder, index, pageIndex, dimColumnEvaluatorInfo, dimensionBlocksIndex[i]);
                if (dimColumnEvaluatorInfo.getDimension().hasEncoding(Encoding.DICTIONARY) && !dimColumnEvaluatorInfo.getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                    memberString = getFilterActualValueFromDictionaryValue(dimColumnEvaluatorInfo, dictionaryValue);
                    record[dimColumnEvaluatorInfo.getRowIndex()] = DataTypeUtil.getDataBasedOnDataType(memberString, dimColumnEvaluatorInfo.getDimension().getDataType());
                } else if (dimColumnEvaluatorInfo.getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                    Object member = getFilterActualValueFromDirectDictionaryValue(dimColumnEvaluatorInfo, dictionaryValue);
                    record[dimColumnEvaluatorInfo.getRowIndex()] = member;
                }
            }
        } else {
            try {
                GenericQueryType complexType = complexDimensionInfoMap.get(dimensionBlocksIndex[i]);
                ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                DataOutputStream dataOutputStream = new DataOutputStream(byteStream);
                complexType.parseBlocksAndReturnComplexColumnByteArray(blockChunkHolder.getDimensionRawDataChunk(), index, pageIndex, dataOutputStream);
                record[dimColumnEvaluatorInfo.getRowIndex()] = complexType.getDataBasedOnDataTypeFromSurrogates(ByteBuffer.wrap(byteStream.toByteArray()));
                byteStream.close();
            } catch (IOException e) {
                LOGGER.info(e.getMessage());
            }
        }
    }
    DataType msrType;
    for (int i = 0; i < msrColEvalutorInfoList.size(); i++) {
        MeasureColumnResolvedFilterInfo msrColumnEvalutorInfo = msrColEvalutorInfoList.get(i);
        switch(msrColumnEvalutorInfo.getType()) {
            case SHORT:
                msrType = DataType.SHORT;
                break;
            case INT:
                msrType = DataType.INT;
                break;
            case LONG:
                msrType = DataType.LONG;
                break;
            case DECIMAL:
                msrType = DataType.DECIMAL;
                break;
            default:
                msrType = DataType.DOUBLE;
        }
        // in the current block measure list
        if (!isMeasurePresentInCurrentBlock[i]) {
            byte[] defaultValue = msrColumnEvalutorInfo.getCarbonColumn().getDefaultValue();
            record[msrColumnEvalutorInfo.getRowIndex()] = RestructureUtil.getMeasureDefaultValue(msrColumnEvalutorInfo.getCarbonColumn().getColumnSchema(), defaultValue);
            continue;
        }
        Object msrValue;
        MeasureColumnDataChunk measureColumnDataChunk = blockChunkHolder.getMeasureRawDataChunk()[measureBlocksIndex[0]].convertToMeasureColDataChunk(pageIndex);
        switch(msrType) {
            case SHORT:
                msrValue = (short) measureColumnDataChunk.getMeasureDataHolder().getReadableLongValueByIndex(index);
                break;
            case INT:
                msrValue = (int) measureColumnDataChunk.getMeasureDataHolder().getReadableLongValueByIndex(index);
                break;
            case LONG:
                msrValue = measureColumnDataChunk.getMeasureDataHolder().getReadableLongValueByIndex(index);
                break;
            case DECIMAL:
                BigDecimal bigDecimalValue = measureColumnDataChunk.getMeasureDataHolder().getReadableBigDecimalValueByIndex(index);
                if (null != bigDecimalValue && msrColumnEvalutorInfo.getCarbonColumn().getColumnSchema().getScale() > bigDecimalValue.scale()) {
                    bigDecimalValue = bigDecimalValue.setScale(msrColumnEvalutorInfo.getCarbonColumn().getColumnSchema().getScale(), RoundingMode.HALF_UP);
                }
                msrValue = bigDecimalValue;
                break;
            default:
                msrValue = measureColumnDataChunk.getMeasureDataHolder().getReadableDoubleValueByIndex(index);
        }
        record[msrColumnEvalutorInfo.getRowIndex()] = measureColumnDataChunk.getNullValueIndexHolder().getBitSet().get(index) ? null : msrValue;
    }
    row.setValues(record);
}
Also used : MeasureColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo) DimColumnResolvedFilterInfo(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo) DataOutputStream(java.io.DataOutputStream) DimensionColumnDataChunk(org.apache.carbondata.core.datastore.chunk.DimensionColumnDataChunk) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MeasureColumnDataChunk(org.apache.carbondata.core.datastore.chunk.MeasureColumnDataChunk) VariableLengthDimensionDataChunk(org.apache.carbondata.core.datastore.chunk.impl.VariableLengthDimensionDataChunk) BigDecimal(java.math.BigDecimal) GenericQueryType(org.apache.carbondata.core.scan.filter.GenericQueryType) DataType(org.apache.carbondata.core.metadata.datatype.DataType)

Example 7 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class PartitionFilterUtil method getPartitionMapForRangeFilter.

/**
   * get partition map of range filter on list partition table
   * @param partitionInfo
   * @param partitioner
   * @param filterValue
   * @param isGreaterThan
   * @param isEqualTo
   * @return
   */
public static BitSet getPartitionMapForRangeFilter(PartitionInfo partitionInfo, ListPartitioner partitioner, Object filterValue, boolean isGreaterThan, boolean isEqualTo) {
    List<List<String>> values = partitionInfo.getListInfo();
    DataType partitionColumnDataType = partitionInfo.getColumnSchemaList().get(0).getDataType();
    Comparator comparator = PartitionFilterUtil.getComparatorByDataType(partitionColumnDataType);
    BitSet partitionMap = PartitionUtil.generateBitSetBySize(partitioner.numPartitions(), false);
    // add default partition
    partitionMap.set(partitioner.numPartitions() - 1);
    int partitions = values.size();
    if (isGreaterThan) {
        if (isEqualTo) {
            // GreaterThanEqualTo(>=)
            outer1: for (int i = 0; i < partitions; i++) {
                for (String value : values.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType);
                    if (comparator.compare(listValue, filterValue) >= 0) {
                        partitionMap.set(i);
                        continue outer1;
                    }
                }
            }
        } else {
            // GreaterThan(>)
            outer2: for (int i = 0; i < partitions; i++) {
                for (String value : values.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType);
                    if (comparator.compare(listValue, filterValue) > 0) {
                        partitionMap.set(i);
                        continue outer2;
                    }
                }
            }
        }
    } else {
        if (isEqualTo) {
            // LessThanEqualTo(<=)
            outer3: for (int i = 0; i < partitions; i++) {
                for (String value : values.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType);
                    if (comparator.compare(listValue, filterValue) <= 0) {
                        partitionMap.set(i);
                        continue outer3;
                    }
                }
            }
        } else {
            // LessThanEqualTo(<)
            outer4: for (int i = 0; i < partitions; i++) {
                for (String value : values.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType);
                    if (comparator.compare(listValue, filterValue) < 0) {
                        partitionMap.set(i);
                        continue outer4;
                    }
                }
            }
        }
    }
    return partitionMap;
}
Also used : BitSet(java.util.BitSet) DataType(org.apache.carbondata.core.metadata.datatype.DataType) List(java.util.List) Comparator(java.util.Comparator)

Example 8 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class PartitionFilterUtil method getPartitionMapForRangeFilter.

/**
   * get partition map of range filter on range partition table
   * @param partitionInfo
   * @param partitioner
   * @param filterValue
   * @param isGreaterThan
   * @param isEqualTo
   * @return
   */
public static BitSet getPartitionMapForRangeFilter(PartitionInfo partitionInfo, RangePartitioner partitioner, Object filterValue, boolean isGreaterThan, boolean isEqualTo) {
    List<String> values = partitionInfo.getRangeInfo();
    DataType partitionColumnDataType = partitionInfo.getColumnSchemaList().get(0).getDataType();
    Comparator comparator = PartitionFilterUtil.getComparatorByDataType(partitionColumnDataType);
    BitSet partitionMap = PartitionUtil.generateBitSetBySize(partitioner.numPartitions(), false);
    int numPartitions = values.size();
    int result = 0;
    // the partition index of filter value
    int partitionIndex = 0;
    // find the partition of filter value
    for (; partitionIndex < numPartitions; partitionIndex++) {
        result = comparator.compare(filterValue, PartitionUtil.getDataBasedOnDataType(values.get(partitionIndex), partitionColumnDataType));
        if (result <= 0) {
            break;
        }
    }
    if (partitionIndex == numPartitions) {
        // filter value is in default partition
        if (isGreaterThan) {
            // GreaterThan(>), GreaterThanEqualTo(>=)
            partitionMap.set(numPartitions);
        } else {
            // LessThan(<), LessThanEqualTo(<=)
            partitionMap.set(0, partitioner.numPartitions());
        }
    } else {
        // filter value is not in default partition
        if (result == 0) {
            // if result is 0, the filter value is a bound value of range partition.
            if (isGreaterThan) {
                // GreaterThan(>), GreaterThanEqualTo(>=)
                partitionMap.set(partitionIndex + 1, partitioner.numPartitions());
            } else {
                if (isEqualTo) {
                    // LessThanEqualTo(<=)
                    partitionMap.set(0, partitionIndex + 2);
                } else {
                    // LessThan(<)
                    partitionMap.set(0, partitionIndex + 1);
                }
            }
        } else {
            // the filter value is not a bound value of range partition
            if (isGreaterThan) {
                // GreaterThan(>), GreaterThanEqualTo(>=)
                partitionMap.set(partitionIndex, partitioner.numPartitions());
            } else {
                // LessThan(<), LessThanEqualTo(<=)
                partitionMap.set(0, partitionIndex + 1);
            }
        }
    }
    return partitionMap;
}
Also used : BitSet(java.util.BitSet) DataType(org.apache.carbondata.core.metadata.datatype.DataType) Comparator(java.util.Comparator)

Example 9 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class ColumnExpressionTest method setUp.

@Before
public void setUp() {
    String columnName = "IMEI";
    DataType dataType = DataType.STRING;
    columnExpression = new ColumnExpression(columnName, dataType);
}
Also used : DataType(org.apache.carbondata.core.metadata.datatype.DataType) Before(org.junit.Before)

Example 10 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class ValueCompressionUtilTest method testToGetValueCompressionModelForByteAndInt.

@Test
public void testToGetValueCompressionModelForByteAndInt() {
    Object[] maxValues = { -32766.00 };
    Object[] minValues = { 32744.0 };
    int[] decimalLength = { 0 };
    Object[] uniqueValues = { 5 };
    DataType[] types = { DataType.DOUBLE };
    byte[] dataTypeSelected = { 1 };
    MeasureMetaDataModel measureMetaDataModel = new MeasureMetaDataModel(maxValues, minValues, decimalLength, 1, uniqueValues, types, dataTypeSelected);
    WriterCompressModel writerCompressModel = ValueCompressionUtil.getWriterCompressModel(measureMetaDataModel);
    assertEquals(ValueCompressionUtil.COMPRESSION_TYPE.ADAPTIVE, writerCompressModel.getCompType(0));
}
Also used : WriterCompressModel(org.apache.carbondata.core.datastore.compression.WriterCompressModel) MeasureMetaDataModel(org.apache.carbondata.core.datastore.compression.MeasureMetaDataModel) DataType(org.apache.carbondata.core.metadata.datatype.DataType) Test(org.junit.Test)

Aggregations

DataType (org.apache.carbondata.core.metadata.datatype.DataType)27 MeasureMetaDataModel (org.apache.carbondata.core.datastore.compression.MeasureMetaDataModel)9 WriterCompressModel (org.apache.carbondata.core.datastore.compression.WriterCompressModel)9 Test (org.junit.Test)8 IOException (java.io.IOException)3 List (java.util.List)3 Domain (com.facebook.presto.spi.predicate.Domain)2 Range (com.facebook.presto.spi.predicate.Range)2 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)2 ImmutableList (com.google.common.collect.ImmutableList)2 DataOutputStream (java.io.DataOutputStream)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 Comparator (java.util.Comparator)2 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)2 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)2 Expression (org.apache.carbondata.core.scan.expression.Expression)2 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)2 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)2