Search in sources :

Example 6 with FieldType

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);
}
Also used : FieldType(com.linkedin.pinot.common.data.FieldSpec.FieldType)

Example 7 with FieldType

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;
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) ColumnMetadata(com.linkedin.pinot.core.segment.index.ColumnMetadata) Schema(com.linkedin.pinot.common.data.Schema) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) DataType(com.linkedin.pinot.common.data.FieldSpec.DataType) TimeUnit(java.util.concurrent.TimeUnit) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec) FieldType(com.linkedin.pinot.common.data.FieldSpec.FieldType)

Example 8 with FieldType

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;
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Schema(com.linkedin.pinot.common.data.Schema) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) DataFileStream(org.apache.avro.file.DataFileStream) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) FileInputStream(java.io.FileInputStream) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec) FieldType(com.linkedin.pinot.common.data.FieldSpec.FieldType) Field(org.apache.avro.Schema.Field) GenericRecord(org.apache.avro.generic.GenericRecord) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec)

Aggregations

FieldType (com.linkedin.pinot.common.data.FieldSpec.FieldType)8 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)5 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 DimensionFieldSpec (com.linkedin.pinot.common.data.DimensionFieldSpec)3 MetricFieldSpec (com.linkedin.pinot.common.data.MetricFieldSpec)3 Schema (com.linkedin.pinot.common.data.Schema)3 TimeFieldSpec (com.linkedin.pinot.common.data.TimeFieldSpec)3 File (java.io.File)3 HashMap (java.util.HashMap)3 TimeUnit (java.util.concurrent.TimeUnit)3 TimeGranularitySpec (com.linkedin.pinot.common.data.TimeGranularitySpec)2 DataGenerator (com.linkedin.pinot.tools.data.generator.DataGenerator)2 DataGeneratorSpec (com.linkedin.pinot.tools.data.generator.DataGeneratorSpec)2 IntRange (org.apache.commons.lang.math.IntRange)2 SegmentGeneratorConfig (com.linkedin.pinot.core.indexsegment.generator.SegmentGeneratorConfig)1 SegmentIndexCreationDriver (com.linkedin.pinot.core.segment.creator.SegmentIndexCreationDriver)1 ColumnMetadata (com.linkedin.pinot.core.segment.index.ColumnMetadata)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1