use of com.linkedin.pinot.common.data.MetricFieldSpec in project pinot by linkedin.
the class SegmentTestUtils method extractSchemaFromAvro.
public static Schema extractSchemaFromAvro(File avroFile, Map<String, FieldType> fieldTypeMap, TimeUnit granularity) throws IOException {
DataFileStream<GenericRecord> dataStream = new DataFileStream<>(new FileInputStream(avroFile), new GenericDatumReader<GenericRecord>());
Schema schema = new Schema();
for (final Field field : dataStream.getSchema().getFields()) {
final String columnName = field.name();
FieldType fieldType = fieldTypeMap.get(columnName);
Preconditions.checkNotNull(fieldType);
switch(fieldType) {
case TIME:
final TimeGranularitySpec gSpec = new TimeGranularitySpec(getColumnType(field), granularity, columnName);
final TimeFieldSpec fSpec = new TimeFieldSpec(gSpec);
schema.addField(fSpec);
continue;
case DIMENSION:
final FieldSpec dimensionFieldSpec = new DimensionFieldSpec(columnName, getColumnType(field), isSingleValueField(field));
schema.addField(dimensionFieldSpec);
continue;
case METRIC:
final FieldSpec metricFieldSpec = new MetricFieldSpec(columnName, getColumnType(field));
schema.addField(metricFieldSpec);
continue;
default:
throw new UnsupportedOperationException("Unsupported field type: " + fieldType);
}
}
dataStream.close();
return schema;
}
use of com.linkedin.pinot.common.data.MetricFieldSpec in project pinot by linkedin.
the class TransformGroupByTest method buildSchema.
/**
* Helper method to build a schema with one string dimension, and one double metric columns.
*/
private static Schema buildSchema() {
Schema schema = new Schema();
DimensionFieldSpec dimensionFieldSpec = new DimensionFieldSpec(DIMENSION_NAME, FieldSpec.DataType.STRING, true);
schema.addField(dimensionFieldSpec);
MetricFieldSpec metricFieldSpec = new MetricFieldSpec(METRIC_NAME, FieldSpec.DataType.DOUBLE);
schema.addField(metricFieldSpec);
TimeFieldSpec timeFieldSpec = new TimeFieldSpec(TIME_COLUMN_NAME, FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS);
schema.setTimeFieldSpec(timeFieldSpec);
return schema;
}
use of com.linkedin.pinot.common.data.MetricFieldSpec in project pinot by linkedin.
the class TransformExpressionOperatorTest method buildSchema.
/**
* Helper method to build a schema with provided number of metric columns.
*
* @param numMetrics Number of metric columns in the schema
* @return Schema containing the given number of metric columns
*/
private static Schema buildSchema(int numMetrics) {
Schema schema = new Schema();
for (int i = 0; i < numMetrics; i++) {
String metricName = "m_" + i;
MetricFieldSpec metricFieldSpec = new MetricFieldSpec(metricName, FieldSpec.DataType.DOUBLE);
schema.addField(metricFieldSpec);
}
return schema;
}
use of com.linkedin.pinot.common.data.MetricFieldSpec in project pinot by linkedin.
the class SegmentIndexCreationDriverImpl method addDerivedFieldsInSchema.
private void addDerivedFieldsInSchema() {
if (createHllIndex) {
Collection<String> columnNames = dataSchema.getColumnNames();
HllConfig hllConfig = config.getHllConfig();
for (String derivedFieldName : hllConfig.getDerivedHllFieldToOriginMap().keySet()) {
if (columnNames.contains(derivedFieldName)) {
throw new IllegalArgumentException("Cannot add derived field: " + derivedFieldName + " since it already exists in schema.");
} else {
dataSchema.addField(new MetricFieldSpec(derivedFieldName, FieldSpec.DataType.STRING, hllConfig.getHllFieldSize(), MetricFieldSpec.DerivedMetricType.HLL));
}
}
}
}
use of com.linkedin.pinot.common.data.MetricFieldSpec in project pinot by linkedin.
the class DefaultAggregationExecutorTest method buildSchema.
/**
* Helper method to build schema for the segment on which aggregation tests will be run.
*
* @return
*/
private Schema buildSchema() {
Schema schema = new Schema();
for (int i = 0; i < NUM_METRIC_COLUMNS; i++) {
String metricName = METRIC_PREFIX + i;
MetricFieldSpec metricFieldSpec = new MetricFieldSpec(metricName, FieldSpec.DataType.DOUBLE);
schema.addField(metricFieldSpec);
_columns[i] = metricName;
}
return schema;
}
Aggregations