Search in sources :

Example 61 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class AbstractQueryExecutor method getBlockExecutionInfoForBlock.

/**
 * Below method will be used to get the block execution info which is
 * required to execute any block  based on query model
 *
 * @param queryModel query model from user query
 * @param blockIndex block index
 * @return block execution info
 */
private BlockExecutionInfo getBlockExecutionInfoForBlock(QueryModel queryModel, AbstractIndex blockIndex, int numberOfBlockletToScan, String filePath, String[] deleteDeltaFiles, Segment segment) {
    BlockExecutionInfo blockExecutionInfo = new BlockExecutionInfo();
    SegmentProperties segmentProperties = blockIndex.getSegmentProperties();
    // set actual query dimensions and measures. It may differ in case of restructure scenarios
    RestructureUtil.actualProjectionOfSegment(blockExecutionInfo, queryModel, segmentProperties);
    // below is to get only those dimension in query which is present in the
    // table block
    List<ProjectionDimension> projectDimensions = RestructureUtil.createDimensionInfoAndGetCurrentBlockQueryDimension(blockExecutionInfo, blockExecutionInfo.getActualQueryDimensions(), segmentProperties.getDimensions(), segmentProperties.getComplexDimensions(), blockExecutionInfo.getActualQueryMeasures().length, queryModel.getTable().getTableInfo().isTransactionalTable(), queryModel);
    boolean isStandardTable = CarbonUtil.isStandardCarbonTable(queryModel.getTable());
    String blockId = CarbonUtil.getBlockId(queryModel.getAbsoluteTableIdentifier(), filePath, segment.getSegmentNo(), queryModel.getTable().getTableInfo().isTransactionalTable(), isStandardTable, queryModel.getTable().isHivePartitionTable());
    blockExecutionInfo.setBlockId(CarbonTablePath.getShortBlockId(blockId));
    blockExecutionInfo.setDeleteDeltaFilePath(deleteDeltaFiles);
    blockExecutionInfo.setStartBlockletIndex(0);
    blockExecutionInfo.setNumberOfBlockletToScan(numberOfBlockletToScan);
    blockExecutionInfo.setProjectionDimensions(projectDimensions.toArray(new ProjectionDimension[0]));
    // get measures present in the current block
    List<ProjectionMeasure> projectionMeasures = RestructureUtil.createMeasureInfoAndGetCurrentBlockQueryMeasures(blockExecutionInfo, blockExecutionInfo.getActualQueryMeasures(), segmentProperties.getMeasures(), queryModel.getTable().getTableInfo().isTransactionalTable(), queryModel);
    blockExecutionInfo.setProjectionMeasures(projectionMeasures.toArray(new ProjectionMeasure[projectionMeasures.size()]));
    blockExecutionInfo.setDataBlock(blockIndex);
    // setting whether raw record query or not
    blockExecutionInfo.setRawRecordDetailQuery(queryModel.isForcedDetailRawQuery());
    // total number dimension
    blockExecutionInfo.setTotalNumberDimensionToRead(segmentProperties.getDimensionOrdinalToChunkMapping().size());
    blockExecutionInfo.setReadOnlyDelta(queryModel.isReadOnlyDelta());
    if (queryModel.isReadPageByPage()) {
        blockExecutionInfo.setPrefetchBlocklet(false);
        LOGGER.info("Query prefetch is: false, read page by page");
    } else {
        LOGGER.info("Query prefetch is: " + queryModel.isPreFetchData());
        blockExecutionInfo.setPrefetchBlocklet(queryModel.isPreFetchData());
    }
    // In case of fg index it should not go to direct fill.
    boolean fgIndexPathPresent = false;
    for (TableBlockInfo blockInfo : queryModel.getTableBlockInfos()) {
        fgIndexPathPresent = blockInfo.getIndexWriterPath() != null;
        if (fgIndexPathPresent) {
            queryModel.setDirectVectorFill(false);
            break;
        }
    }
    blockExecutionInfo.setDirectVectorFill(queryModel.isDirectVectorFill());
    blockExecutionInfo.setTotalNumberOfMeasureToRead(segmentProperties.getMeasuresOrdinalToChunkMapping().size());
    blockExecutionInfo.setComplexDimensionInfoMap(QueryUtil.getComplexDimensionsMap(projectDimensions, segmentProperties.getDimensionOrdinalToChunkMapping(), queryProperties.complexFilterDimension));
    if (null != queryModel.getIndexFilter()) {
        FilterResolverIntf filterResolverIntf;
        if (!filePath.startsWith(queryModel.getTable().getTablePath())) {
            filterResolverIntf = queryModel.getIndexFilter().getExternalSegmentResolver();
        } else {
            // loading the filter executor tree for filter evaluation
            filterResolverIntf = queryModel.getIndexFilter().getResolver();
        }
        blockExecutionInfo.setFilterExecutorTree(FilterUtil.getFilterExecutorTree(filterResolverIntf, segmentProperties, blockExecutionInfo.getComplexDimensionInfoMap(), false));
    }
    // expression measure
    List<CarbonMeasure> expressionMeasures = new ArrayList<CarbonMeasure>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    // setting all the dimension chunk indexes to be read from file
    int numberOfElementToConsider = 0;
    // list of dimensions to be projected
    Set<Integer> allProjectionListDimensionIndexes = new LinkedHashSet<>();
    // create a list of filter dimensions present in the current block
    Set<CarbonDimension> currentBlockFilterDimensions = getCurrentBlockFilterDimensions(queryProperties.complexFilterDimension, segmentProperties);
    int[] dimensionChunkIndexes = QueryUtil.getDimensionChunkIndexes(projectDimensions, segmentProperties.getDimensionOrdinalToChunkMapping(), currentBlockFilterDimensions, allProjectionListDimensionIndexes);
    ReusableDataBuffer[] dimensionBuffer = new ReusableDataBuffer[reusableDimensionBufferSize];
    for (int i = 0; i < dimensionBuffer.length; i++) {
        dimensionBuffer[i] = new ReusableDataBuffer();
    }
    blockExecutionInfo.setDimensionReusableDataBuffer(dimensionBuffer);
    int numberOfColumnToBeReadInOneIO = Integer.parseInt(CarbonProperties.getInstance().getProperty(CarbonV3DataFormatConstants.NUMBER_OF_COLUMN_TO_READ_IN_IO, CarbonV3DataFormatConstants.NUMBER_OF_COLUMN_TO_READ_IN_IO_DEFAULT_VALUE));
    if (dimensionChunkIndexes.length > 0) {
        numberOfElementToConsider = dimensionChunkIndexes[dimensionChunkIndexes.length - 1] == segmentProperties.getBlockToDimensionOrdinalMapping().size() - 1 ? dimensionChunkIndexes.length - 1 : dimensionChunkIndexes.length;
        blockExecutionInfo.setAllSelectedDimensionColumnIndexRange(CarbonUtil.getRangeIndex(dimensionChunkIndexes, numberOfElementToConsider, numberOfColumnToBeReadInOneIO));
    } else {
        blockExecutionInfo.setAllSelectedDimensionColumnIndexRange(new int[0][0]);
    }
    // get the list of updated filter measures present in the current block
    Set<CarbonMeasure> filterMeasures = getCurrentBlockFilterMeasures(queryProperties.filterMeasures, segmentProperties);
    // list of measures to be projected
    List<Integer> allProjectionListMeasureIndexes = new ArrayList<>();
    int[] measureChunkIndexes = QueryUtil.getMeasureChunkIndexes(projectionMeasures, expressionMeasures, segmentProperties.getMeasuresOrdinalToChunkMapping(), filterMeasures, allProjectionListMeasureIndexes);
    ReusableDataBuffer[] measureBuffer = new ReusableDataBuffer[allProjectionListMeasureIndexes.size()];
    for (int i = 0; i < measureBuffer.length; i++) {
        measureBuffer[i] = new ReusableDataBuffer();
    }
    blockExecutionInfo.setMeasureReusableDataBuffer(measureBuffer);
    if (measureChunkIndexes.length > 0) {
        numberOfElementToConsider = measureChunkIndexes[measureChunkIndexes.length - 1] == segmentProperties.getMeasures().size() - 1 ? measureChunkIndexes.length - 1 : measureChunkIndexes.length;
        // setting all the measure chunk indexes to be read from file
        blockExecutionInfo.setAllSelectedMeasureIndexRange(CarbonUtil.getRangeIndex(measureChunkIndexes, numberOfElementToConsider, numberOfColumnToBeReadInOneIO));
    } else {
        blockExecutionInfo.setAllSelectedMeasureIndexRange(new int[0][0]);
    }
    // setting the indexes of list of dimension in projection list
    blockExecutionInfo.setProjectionListDimensionIndexes(ArrayUtils.toPrimitive(allProjectionListDimensionIndexes.toArray(new Integer[allProjectionListDimensionIndexes.size()])));
    // setting the indexes of list of measures in projection list
    blockExecutionInfo.setProjectionListMeasureIndexes(ArrayUtils.toPrimitive(allProjectionListMeasureIndexes.toArray(new Integer[allProjectionListMeasureIndexes.size()])));
    // setting the size of fixed key column (dictionary column)
    blockExecutionInfo.setFixedLengthKeySize(getKeySize(projectDimensions, segmentProperties));
    List<Integer> dictionaryColumnChunkIndex = new ArrayList<Integer>();
    List<Integer> noDictionaryColumnChunkIndex = new ArrayList<Integer>();
    // get the block index to be read from file for query dimension
    // for both dictionary columns and no dictionary columns
    QueryUtil.fillQueryDimensionChunkIndexes(projectDimensions, segmentProperties.getDimensionOrdinalToChunkMapping(), dictionaryColumnChunkIndex, noDictionaryColumnChunkIndex);
    int[] queryDictionaryColumnChunkIndexes = ArrayUtils.toPrimitive(dictionaryColumnChunkIndex.toArray(new Integer[dictionaryColumnChunkIndex.size()]));
    // column key will be filled based on key order
    if (!queryModel.isForcedDetailRawQuery()) {
        Arrays.sort(queryDictionaryColumnChunkIndexes);
    }
    blockExecutionInfo.setDictionaryColumnChunkIndex(queryDictionaryColumnChunkIndexes);
    // setting the no dictionary column block indexes
    blockExecutionInfo.setNoDictionaryColumnChunkIndexes(ArrayUtils.toPrimitive(noDictionaryColumnChunkIndex.toArray(new Integer[noDictionaryColumnChunkIndex.size()])));
    blockExecutionInfo.setComplexColumnParentBlockIndexes(getComplexDimensionParentBlockIndexes(projectDimensions));
    blockExecutionInfo.setVectorBatchCollector(queryModel.isVectorReader());
    DataTypeUtil.setDataTypeConverter(queryModel.getConverter());
    blockExecutionInfo.setRequiredRowId(queryModel.isRequiredRowId());
    return blockExecutionInfo;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) ArrayList(java.util.ArrayList) ProjectionDimension(org.apache.carbondata.core.scan.model.ProjectionDimension) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ProjectionMeasure(org.apache.carbondata.core.scan.model.ProjectionMeasure) ReusableDataBuffer(org.apache.carbondata.core.datastore.ReusableDataBuffer) BlockExecutionInfo(org.apache.carbondata.core.scan.executor.infos.BlockExecutionInfo) SegmentProperties(org.apache.carbondata.core.datastore.block.SegmentProperties) FilterResolverIntf(org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf)

Example 62 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class RestructureBasedVectorResultCollector method fillDataForNonExistingMeasures.

/**
 * This method will fill the default values of non existing measures in the current block
 */
private void fillDataForNonExistingMeasures() {
    for (int i = 0; i < executionInfo.getActualQueryMeasures().length; i++) {
        if (!measureInfo.getMeasureExists()[i]) {
            int queryOrder = executionInfo.getActualQueryMeasures()[i].getOrdinal();
            CarbonMeasure measure = executionInfo.getActualQueryMeasures()[i].getMeasure();
            ColumnVectorInfo columnVectorInfo = allColumnInfo[queryOrder];
            CarbonColumnVector vector = columnVectorInfo.vector;
            Object defaultValue = measureDefaultValues[i];
            if (null == defaultValue) {
                vector.putNulls(columnVectorInfo.vectorOffset, columnVectorInfo.size);
            } else {
                DataType dataType = measureInfo.getMeasureDataTypes()[i];
                if (dataType == DataTypes.SHORT) {
                    vector.putShorts(columnVectorInfo.vectorOffset, columnVectorInfo.size, (short) defaultValue);
                } else if (dataType == DataTypes.INT) {
                    vector.putInts(columnVectorInfo.vectorOffset, columnVectorInfo.size, (int) defaultValue);
                } else if (dataType == DataTypes.LONG) {
                    vector.putLongs(columnVectorInfo.vectorOffset, columnVectorInfo.size, (long) defaultValue);
                } else if (DataTypes.isDecimal(dataType)) {
                    vector.putDecimals(columnVectorInfo.vectorOffset, columnVectorInfo.size, (BigDecimal) defaultValue, measure.getPrecision());
                } else if (dataType == DataTypes.BOOLEAN) {
                    vector.putBoolean(columnVectorInfo.vectorOffset, (Boolean) defaultValue);
                } else {
                    vector.putDoubles(columnVectorInfo.vectorOffset, columnVectorInfo.size, (double) defaultValue);
                }
            }
        }
    }
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ColumnVectorInfo(org.apache.carbondata.core.scan.result.vector.ColumnVectorInfo) DataType(org.apache.carbondata.core.metadata.datatype.DataType) CarbonColumnVector(org.apache.carbondata.core.scan.result.vector.CarbonColumnVector) BigDecimal(java.math.BigDecimal)

Example 63 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class SegmentProperties method fillDimensionAndMeasureDetails.

/**
 * below method will fill dimension and measure detail of the block.
 *
 * @param columnsInTable
 */
private void fillDimensionAndMeasureDetails(List<ColumnSchema> columnsInTable) {
    ColumnSchema columnSchema = null;
    // ordinal will be required to read the data from file block
    int dimensionOrdinal = 0;
    int measureOrdinal = -1;
    // table ordinal is actually a schema ordinal this is required as
    // cardinality array
    // which is stored in segment info contains -1 if that particular column
    // is n
    boolean isComplexDimensionStarted = false;
    CarbonDimension carbonDimension = null;
    int keyOrdinal = 0;
    int counter = 0;
    int complexTypeOrdinal = -1;
    while (counter < columnsInTable.size()) {
        columnSchema = columnsInTable.get(counter);
        if (columnSchema.isDimensionColumn()) {
            // column as it was not the part of MDKey
            if (CarbonUtil.hasEncoding(columnSchema.getEncodingList(), Encoding.DICTIONARY) && !isComplexDimensionStarted && columnSchema.getNumberOfChild() == 0) {
                this.numberOfDictDimensions++;
                this.numberOfColumnsAfterFlatten++;
                if (columnSchema.isSortColumn()) {
                    this.numberOfSortColumns++;
                }
                // if it is a columnar dimension participated in MDKey then added
                // key ordinal and dimension ordinal
                carbonDimension = new CarbonDimension(columnSchema, dimensionOrdinal++, keyOrdinal++, -1);
            } else // will be added to complex type
            if (isComplexDimensionStarted || columnSchema.getDataType().isComplexType()) {
                carbonDimension = new CarbonDimension(columnSchema, dimensionOrdinal++, -1, ++complexTypeOrdinal);
                carbonDimension.initializeChildDimensionsList(columnSchema.getNumberOfChild());
                complexDimensions.add(carbonDimension);
                isComplexDimensionStarted = true;
                dimensionOrdinal = readAllComplexTypeChildren(dimensionOrdinal, columnSchema.getNumberOfChild(), columnsInTable, carbonDimension, complexTypeOrdinal);
                counter = dimensionOrdinal;
                complexTypeOrdinal = assignComplexOrdinal(carbonDimension, complexTypeOrdinal);
                this.numberOfColumnsAfterFlatten += getNumColumnsAfterFlatten(carbonDimension);
                continue;
            } else {
                // for no dictionary dimension
                carbonDimension = new CarbonDimension(columnSchema, dimensionOrdinal++, -1, -1);
                numberOfColumnsAfterFlatten++;
                numberOfNoDictionaryDimension++;
                if (columnSchema.isSortColumn()) {
                    this.numberOfSortColumns++;
                }
            }
            dimensions.add(carbonDimension);
        } else {
            numberOfColumnsAfterFlatten++;
            measures.add(new CarbonMeasure(columnSchema, ++measureOrdinal));
        }
        counter++;
    }
    lastDimensionColOrdinal = dimensionOrdinal;
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 64 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class SegmentProperties method createColumnValueLength.

/**
 * Return column value length in byte for all columns in the table
 * for dimension and complex column it is -1 (for DATE it is 4),
 * for measure is 8 (for decimal is -1)
 */
public int[] createColumnValueLength() {
    int[] length = new int[numberOfColumnsAfterFlatten];
    int index = 0;
    for (CarbonDimension dimension : dimensions) {
        DataType dataType = dimension.getDataType();
        if (dataType == DataTypes.DATE) {
            length[index] = 4;
        } else {
            length[index] = -1;
        }
        index++;
    }
    for (CarbonDimension complexDimension : complexDimensions) {
        int depth = getNumColumnsAfterFlatten(complexDimension);
        for (int i = 0; i < depth; i++) {
            length[index++] = -1;
        }
    }
    for (CarbonMeasure measure : measures) {
        DataType dataType = measure.getDataType();
        if (DataTypes.isDecimal(dataType)) {
            length[index++] = -1;
        } else {
            length[index++] = 8;
        }
    }
    return length;
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) DataType(org.apache.carbondata.core.metadata.datatype.DataType) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 65 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.

the class TableSpec method addMeasures.

private void addMeasures(List<CarbonMeasure> measures) {
    for (int i = 0; i < measures.size(); i++) {
        CarbonMeasure measure = measures.get(i);
        measureSpec[i] = new MeasureSpec(measure.getColName(), measure.getDataType());
    }
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)

Aggregations

CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)74 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)52 ArrayList (java.util.ArrayList)28 DataType (org.apache.carbondata.core.metadata.datatype.DataType)12 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)12 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)11 HashSet (java.util.HashSet)8 ProjectionMeasure (org.apache.carbondata.core.scan.model.ProjectionMeasure)8 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)7 BlockExecutionInfo (org.apache.carbondata.core.scan.executor.infos.BlockExecutionInfo)5 ProjectionDimension (org.apache.carbondata.core.scan.model.ProjectionDimension)5 SerializableComparator (org.apache.carbondata.core.util.comparator.SerializableComparator)5 MeasureInfo (org.apache.carbondata.core.scan.executor.infos.MeasureInfo)4 DimColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo)4 MeasureColumnResolvedFilterInfo (org.apache.carbondata.core.scan.filter.resolver.resolverinfo.MeasureColumnResolvedFilterInfo)4 BitSet (java.util.BitSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 SegmentProperties (org.apache.carbondata.core.datastore.block.SegmentProperties)3 QueryDimension (org.apache.carbondata.core.scan.model.QueryDimension)3