use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.
the class RestructureUtilTest method testToGetAggregatorInfos.
@Test
public void testToGetAggregatorInfos() {
ColumnSchema columnSchema1 = new ColumnSchema();
columnSchema1.setColumnName("Id");
columnSchema1.setDataType(DataType.STRING);
columnSchema1.setColumnUniqueId(UUID.randomUUID().toString());
ColumnSchema columnSchema2 = new ColumnSchema();
columnSchema2.setColumnName("Name");
columnSchema2.setDataType(DataType.STRING);
columnSchema2.setColumnUniqueId(UUID.randomUUID().toString());
ColumnSchema columnSchema3 = new ColumnSchema();
columnSchema3.setColumnName("Age");
columnSchema3.setDataType(DataType.STRING);
columnSchema3.setColumnUniqueId(UUID.randomUUID().toString());
CarbonMeasure carbonMeasure1 = new CarbonMeasure(columnSchema1, 1);
CarbonMeasure carbonMeasure2 = new CarbonMeasure(columnSchema2, 2);
CarbonMeasure carbonMeasure3 = new CarbonMeasure(columnSchema3, 3);
carbonMeasure3.getColumnSchema().setDefaultValue("3".getBytes());
List<CarbonMeasure> currentBlockMeasures = Arrays.asList(carbonMeasure1, carbonMeasure2);
QueryMeasure queryMeasure1 = new QueryMeasure("Id");
queryMeasure1.setMeasure(carbonMeasure1);
QueryMeasure queryMeasure2 = new QueryMeasure("Name");
queryMeasure2.setMeasure(carbonMeasure2);
QueryMeasure queryMeasure3 = new QueryMeasure("Age");
queryMeasure3.setMeasure(carbonMeasure3);
List<QueryMeasure> queryMeasures = Arrays.asList(queryMeasure1, queryMeasure2, queryMeasure3);
BlockExecutionInfo blockExecutionInfo = new BlockExecutionInfo();
RestructureUtil.createMeasureInfoAndGetCurrentBlockQueryMeasures(blockExecutionInfo, queryMeasures, currentBlockMeasures);
MeasureInfo measureInfo = blockExecutionInfo.getMeasureInfo();
boolean[] measuresExist = { true, true, false };
assertThat(measureInfo.getMeasureExists(), is(equalTo(measuresExist)));
Object[] defaultValues = { null, null, 3.0 };
assertThat(measureInfo.getDefaultValues(), is(equalTo(defaultValues)));
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.
the class DataTypeUtilTest method testGetMeasureValueBasedOnDataType.
@Test
public void testGetMeasureValueBasedOnDataType() {
ColumnSchema columnSchema = new ColumnSchema();
CarbonMeasure carbonMeasure = new CarbonMeasure(columnSchema, 1);
Object resultInt = getMeasureValueBasedOnDataType("1", DataType.INT, carbonMeasure);
Object expectedInt = Double.valueOf(1).intValue();
assertEquals(expectedInt, resultInt);
Object resultLong = getMeasureValueBasedOnDataType("1", DataType.LONG, carbonMeasure);
Object expectedLong = Long.valueOf(1);
assertEquals(expectedLong, resultLong);
Object resultDefault = getMeasureValueBasedOnDataType("1", DataType.DOUBLE, carbonMeasure);
Double expectedDefault = Double.valueOf(1);
assertEquals(expectedDefault, resultDefault);
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.
the class CarbonDataProcessorUtil method getSchemaColumnNames.
/**
* This method update the column Name
*
* @param schema
* @param tableName
*/
public static Set<String> getSchemaColumnNames(CarbonDataLoadSchema schema, String tableName) {
Set<String> columnNames = new HashSet<String>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
String factTableName = schema.getCarbonTable().getFactTableName();
if (tableName.equals(factTableName)) {
List<CarbonDimension> dimensions = schema.getCarbonTable().getDimensionByTableName(factTableName);
for (CarbonDimension dimension : dimensions) {
columnNames.add(dimension.getColName());
}
List<CarbonMeasure> measures = schema.getCarbonTable().getMeasureByTableName(factTableName);
for (CarbonMeasure msr : measures) {
columnNames.add(msr.getColName());
}
} else {
List<CarbonDimension> dimensions = schema.getCarbonTable().getDimensionByTableName(tableName);
for (CarbonDimension dimension : dimensions) {
columnNames.add(dimension.getColName());
}
List<CarbonMeasure> measures = schema.getCarbonTable().getMeasureByTableName(tableName);
for (CarbonMeasure msr : measures) {
columnNames.add(msr.getColName());
}
}
return columnNames;
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.
the class CarbonDataProcessorUtil method getMeasureDataType.
public static DataType[] getMeasureDataType(int measureCount, String databaseName, String tableName) {
DataType[] type = new DataType[measureCount];
for (int i = 0; i < type.length; i++) {
type[i] = DataType.DOUBLE;
}
CarbonTable carbonTable = CarbonMetadata.getInstance().getCarbonTable(databaseName + CarbonCommonConstants.UNDERSCORE + tableName);
List<CarbonMeasure> measures = carbonTable.getMeasureByTableName(tableName);
for (int i = 0; i < type.length; i++) {
type[i] = measures.get(i).getDataType();
}
return type;
}
use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure in project carbondata by apache.
the class CarbonCompactionExecutor method prepareQueryModel.
/**
* Preparing of the query model.
*
* @param blockList
* @return
*/
private QueryModel prepareQueryModel(List<TableBlockInfo> blockList) {
QueryModel model = new QueryModel();
model.setTableBlockInfos(blockList);
model.setForcedDetailRawQuery(true);
model.setFilterExpressionResolverTree(null);
List<QueryDimension> dims = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
List<CarbonDimension> dimensions = carbonTable.getDimensionByTableName(carbonTable.getFactTableName());
for (CarbonDimension dim : dimensions) {
// check if dimension is deleted
QueryDimension queryDimension = new QueryDimension(dim.getColName());
queryDimension.setDimension(dim);
dims.add(queryDimension);
}
model.setQueryDimension(dims);
List<QueryMeasure> msrs = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
List<CarbonMeasure> measures = carbonTable.getMeasureByTableName(carbonTable.getFactTableName());
for (CarbonMeasure carbonMeasure : measures) {
// check if measure is deleted
QueryMeasure queryMeasure = new QueryMeasure(carbonMeasure.getColName());
queryMeasure.setMeasure(carbonMeasure);
msrs.add(queryMeasure);
}
model.setQueryMeasures(msrs);
model.setQueryId(System.nanoTime() + "");
model.setAbsoluteTableIdentifier(carbonTable.getAbsoluteTableIdentifier());
model.setTable(carbonTable);
return model;
}
Aggregations