use of com.linkedin.pinot.common.data.FieldSpec.FieldType in project pinot by linkedin.
the class Schema method addField.
public void addField(@Nonnull FieldSpec fieldSpec) {
Preconditions.checkNotNull(fieldSpec);
String columnName = fieldSpec.getName();
Preconditions.checkNotNull(columnName);
Preconditions.checkState(!fieldSpecMap.containsKey(columnName), "Field spec already exists for column: " + columnName);
FieldType fieldType = fieldSpec.getFieldType();
switch(fieldType) {
case DIMENSION:
dimensions.add(columnName);
dimensionFieldSpecs.add((DimensionFieldSpec) fieldSpec);
break;
case METRIC:
metrics.add(columnName);
metricFieldSpecs.add((MetricFieldSpec) fieldSpec);
break;
case TIME:
Preconditions.checkState(timeFieldSpec == null, "Already defined the time column: " + timeFieldSpec);
timeFieldSpec = (TimeFieldSpec) fieldSpec;
break;
default:
throw new UnsupportedOperationException("Unsupported field type: " + fieldType);
}
fieldSpecMap.put(columnName, fieldSpec);
}
use of com.linkedin.pinot.common.data.FieldSpec.FieldType in project pinot by linkedin.
the class PinotSegmentRecordReader method getSchema.
@Override
public Schema getSchema() {
Schema schema = new Schema();
schema.setSchemaName(segmentMetadata.getName());
for (String column : columns) {
ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataFor(column);
String columnName = columnMetadata.getColumnName();
DataType dataType = columnMetadata.getDataType();
FieldType fieldType = columnMetadata.getFieldType();
FieldSpec fieldSpec = null;
switch(fieldType) {
case DIMENSION:
boolean isSingleValue = columnMetadata.isSingleValue();
fieldSpec = new DimensionFieldSpec(columnName, dataType, isSingleValue);
break;
case METRIC:
fieldSpec = new MetricFieldSpec(columnName, dataType);
break;
case TIME:
TimeUnit timeType = columnMetadata.getTimeUnit();
TimeGranularitySpec incomingGranularitySpec = new TimeGranularitySpec(dataType, timeType, columnName);
fieldSpec = new TimeFieldSpec(incomingGranularitySpec);
break;
default:
break;
}
schema.addField(fieldSpec);
}
return schema;
}
use of com.linkedin.pinot.common.data.FieldSpec.FieldType 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;
}
Aggregations