Search in sources :

Example 16 with MetricFieldSpec

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

Example 17 with MetricFieldSpec

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;
}
Also used : Schema(com.linkedin.pinot.common.data.Schema) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec)

Example 18 with MetricFieldSpec

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

Example 19 with MetricFieldSpec

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));
            }
        }
    }
}
Also used : HllConfig(com.linkedin.pinot.core.startree.hll.HllConfig) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec)

Example 20 with MetricFieldSpec

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

Aggregations

MetricFieldSpec (com.linkedin.pinot.common.data.MetricFieldSpec)25 DimensionFieldSpec (com.linkedin.pinot.common.data.DimensionFieldSpec)16 TimeFieldSpec (com.linkedin.pinot.common.data.TimeFieldSpec)14 Schema (com.linkedin.pinot.common.data.Schema)13 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)11 TimeGranularitySpec (com.linkedin.pinot.common.data.TimeGranularitySpec)6 DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)4 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)4 File (java.io.File)4 FieldType (com.linkedin.pinot.common.data.FieldSpec.FieldType)3 GenericRow (com.linkedin.pinot.core.data.GenericRow)3 HashMap (java.util.HashMap)3 Field (org.apache.avro.Schema.Field)3 Test (org.testng.annotations.Test)3 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)2 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)2 FileInputStream (java.io.FileInputStream)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 DataFileStream (org.apache.avro.file.DataFileStream)2