Search in sources :

Example 21 with CarbonMeasure

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

the class CarbonTable method fillVisibleMeasures.

/**
   * This method will all the visible allMeasures
   *
   * @param tableName
   */
private void fillVisibleMeasures(String tableName) {
    List<CarbonMeasure> visibleMeasures = new ArrayList<CarbonMeasure>(allMeasures.size());
    for (CarbonMeasure measure : allMeasures) {
        if (!measure.isInvisible()) {
            visibleMeasures.add(measure);
        }
    }
    tableMeasuresMap.put(tableName, visibleMeasures);
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)

Example 22 with CarbonMeasure

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

the class CarbonUtilTest method testToGetColumnSchemaList.

@Test
public void testToGetColumnSchemaList() {
    ColumnSchema column1Schema = new ColumnSchema();
    ColumnSchema column2Schema = new ColumnSchema();
    column1Schema.setColumnName("Column1");
    column2Schema.setColumnName("Column2");
    List<CarbonDimension> carbonDimension = new ArrayList<>();
    carbonDimension.add(new CarbonDimension(column1Schema, 1, 1, 1, 1));
    carbonDimension.add(new CarbonDimension(column2Schema, 2, 2, 2, 1));
    List<CarbonMeasure> carbonMeasure = new ArrayList<>();
    carbonMeasure.add(new CarbonMeasure(column1Schema, 1));
    carbonMeasure.add(new CarbonMeasure(column2Schema, 2));
    List<ColumnSchema> columnSchema = CarbonUtil.getColumnSchemaList(carbonDimension, carbonMeasure);
    for (int i = 0; i < carbonMeasure.size(); i++) {
        assertEquals(columnSchema.get(i), carbonMeasure.get(i).getColumnSchema());
    }
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Test(org.junit.Test)

Example 23 with CarbonMeasure

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

the class RestructureUtil method createMeasureInfoAndGetCurrentBlockQueryMeasures.

/**
   * Below method will be used to prepare the measure info object
   * in this method some of the properties which will be extracted
   * from query measure and current block measures will be set
   *
   * @param blockExecutionInfo
   * @param queryMeasures        measures present in query
   * @param currentBlockMeasures current block measures
   * @return measures present in the block
   */
public static List<QueryMeasure> createMeasureInfoAndGetCurrentBlockQueryMeasures(BlockExecutionInfo blockExecutionInfo, List<QueryMeasure> queryMeasures, List<CarbonMeasure> currentBlockMeasures) {
    MeasureInfo measureInfo = new MeasureInfo();
    List<QueryMeasure> presentMeasure = new ArrayList<>(queryMeasures.size());
    int numberOfMeasureInQuery = queryMeasures.size();
    List<Integer> measureOrdinalList = new ArrayList<>(numberOfMeasureInQuery);
    Object[] defaultValues = new Object[numberOfMeasureInQuery];
    boolean[] measureExistsInCurrentBlock = new boolean[numberOfMeasureInQuery];
    int index = 0;
    for (QueryMeasure queryMeasure : queryMeasures) {
        // otherwise adding a default value of a measure
        for (CarbonMeasure carbonMeasure : currentBlockMeasures) {
            if (carbonMeasure.getColumnId().equals(queryMeasure.getMeasure().getColumnId())) {
                QueryMeasure currentBlockMeasure = new QueryMeasure(carbonMeasure.getColName());
                carbonMeasure.getColumnSchema().setDataType(queryMeasure.getMeasure().getDataType());
                carbonMeasure.getColumnSchema().setPrecision(queryMeasure.getMeasure().getPrecision());
                carbonMeasure.getColumnSchema().setScale(queryMeasure.getMeasure().getScale());
                carbonMeasure.getColumnSchema().setDefaultValue(queryMeasure.getMeasure().getDefaultValue());
                currentBlockMeasure.setMeasure(carbonMeasure);
                currentBlockMeasure.setQueryOrder(queryMeasure.getQueryOrder());
                presentMeasure.add(currentBlockMeasure);
                measureOrdinalList.add(carbonMeasure.getOrdinal());
                measureExistsInCurrentBlock[index] = true;
                break;
            }
        }
        if (!measureExistsInCurrentBlock[index]) {
            defaultValues[index] = getMeasureDefaultValue(queryMeasure.getMeasure().getColumnSchema(), queryMeasure.getMeasure().getDefaultValue());
            blockExecutionInfo.setRestructuredBlock(true);
        }
        index++;
    }
    int[] measureOrdinals = ArrayUtils.toPrimitive(measureOrdinalList.toArray(new Integer[measureOrdinalList.size()]));
    measureInfo.setDefaultValues(defaultValues);
    measureInfo.setMeasureOrdinals(measureOrdinals);
    measureInfo.setMeasureExists(measureExistsInCurrentBlock);
    blockExecutionInfo.setMeasureInfo(measureInfo);
    return presentMeasure;
}
Also used : MeasureInfo(org.apache.carbondata.core.scan.executor.infos.MeasureInfo) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) QueryMeasure(org.apache.carbondata.core.scan.model.QueryMeasure) ArrayList(java.util.ArrayList)

Example 24 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 < tableBlockExecutionInfos.getActualQueryMeasures().length; i++) {
        if (!measureInfo.getMeasureExists()[i]) {
            int queryOrder = tableBlockExecutionInfos.getActualQueryMeasures()[i].getQueryOrder();
            CarbonMeasure measure = tableBlockExecutionInfos.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 {
                switch(measureInfo.getMeasureDataTypes()[i]) {
                    case SHORT:
                        vector.putShorts(columnVectorInfo.vectorOffset, columnVectorInfo.size, (short) defaultValue);
                        break;
                    case INT:
                        vector.putInts(columnVectorInfo.vectorOffset, columnVectorInfo.size, (int) defaultValue);
                        break;
                    case LONG:
                        vector.putLongs(columnVectorInfo.vectorOffset, columnVectorInfo.size, (long) defaultValue);
                        break;
                    case DECIMAL:
                        vector.putDecimals(columnVectorInfo.vectorOffset, columnVectorInfo.size, (Decimal) defaultValue, measure.getPrecision());
                        break;
                    default:
                        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) CarbonColumnVector(org.apache.carbondata.core.scan.result.vector.CarbonColumnVector)

Aggregations

CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)24 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)15 ArrayList (java.util.ArrayList)10 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)8 QueryMeasure (org.apache.carbondata.core.scan.model.QueryMeasure)5 HashSet (java.util.HashSet)4 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)4 DataType (org.apache.carbondata.core.metadata.datatype.DataType)3 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)3 QueryDimension (org.apache.carbondata.core.scan.model.QueryDimension)3 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 Set (java.util.Set)2 Cache (org.apache.carbondata.core.cache.Cache)2 Dictionary (org.apache.carbondata.core.cache.dictionary.Dictionary)2 DictionaryColumnUniqueIdentifier (org.apache.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier)2 ColumnIdentifier (org.apache.carbondata.core.metadata.ColumnIdentifier)2 BlockExecutionInfo (org.apache.carbondata.core.scan.executor.infos.BlockExecutionInfo)2 MeasureInfo (org.apache.carbondata.core.scan.executor.infos.MeasureInfo)2