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);
}
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());
}
}
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;
}
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);
}
}
}
}
}
Aggregations