Search in sources :

Example 1 with TimeGranularitySpec

use of com.linkedin.pinot.common.data.TimeGranularitySpec in project pinot by linkedin.

the class ThirdEyeUtils method createSchema.

public static Schema createSchema(CollectionSchema collectionSchema) {
    Schema schema = new Schema();
    for (DimensionSpec dimensionSpec : collectionSchema.getDimensions()) {
        FieldSpec fieldSpec = new DimensionFieldSpec();
        String dimensionName = dimensionSpec.getName();
        fieldSpec.setName(dimensionName);
        fieldSpec.setDataType(DataType.STRING);
        fieldSpec.setSingleValueField(true);
        schema.addField(dimensionName, fieldSpec);
    }
    for (MetricSpec metricSpec : collectionSchema.getMetrics()) {
        FieldSpec fieldSpec = new MetricFieldSpec();
        String metricName = metricSpec.getName();
        fieldSpec.setName(metricName);
        fieldSpec.setDataType(DataType.valueOf(metricSpec.getType().toString()));
        fieldSpec.setSingleValueField(true);
        schema.addField(metricName, fieldSpec);
    }
    TimeSpec timeSpec = collectionSchema.getTime();
    String timeFormat = timeSpec.getFormat().equals("sinceEpoch") ? TimeFormat.EPOCH.toString() : TimeFormat.SIMPLE_DATE_FORMAT.toString() + ":" + timeSpec.getFormat();
    TimeGranularitySpec incoming = new TimeGranularitySpec(DataType.LONG, timeSpec.getDataGranularity().getSize(), timeSpec.getDataGranularity().getUnit(), timeFormat, timeSpec.getColumnName());
    TimeGranularitySpec outgoing = new TimeGranularitySpec(DataType.LONG, timeSpec.getDataGranularity().getSize(), timeSpec.getDataGranularity().getUnit(), timeFormat, timeSpec.getColumnName());
    schema.addField(timeSpec.getColumnName(), new TimeFieldSpec(incoming, outgoing));
    schema.setSchemaName(collectionSchema.getCollection());
    return schema;
}
Also used : DimensionSpec(com.linkedin.thirdeye.api.DimensionSpec) TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Schema(com.linkedin.pinot.common.data.Schema) CollectionSchema(com.linkedin.thirdeye.api.CollectionSchema) MetricSpec(com.linkedin.thirdeye.api.MetricSpec) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) 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) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Example 2 with TimeGranularitySpec

use of com.linkedin.pinot.common.data.TimeGranularitySpec in project pinot by linkedin.

the class DefaultTimeConverterTest method testWithDifferentTimeSpecButSameValue.

@Test
public void testWithDifferentTimeSpecButSameValue() {
    TimeGranularitySpec incoming = new TimeGranularitySpec(LONG, 2, DAYS, "2days");
    TimeGranularitySpec outgoing = new TimeGranularitySpec(LONG, 48, HOURS, "48hours");
    DefaultTimeConverter timeConverter = new DefaultTimeConverter();
    timeConverter.init(incoming, outgoing);
    for (int i = 0; i < 1000; ++i) {
        Object convertedValue = timeConverter.convert(i);
        Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
        Assert.assertEquals(((Long) convertedValue).intValue(), i);
    }
    for (long i = 0; i < 1000; ++i) {
        Object convertedValue = timeConverter.convert(i);
        Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
        Assert.assertEquals(((Long) convertedValue).longValue(), i);
    }
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Test(org.testng.annotations.Test)

Example 3 with TimeGranularitySpec

use of com.linkedin.pinot.common.data.TimeGranularitySpec in project pinot by linkedin.

the class DefaultTimeConverterTest method testWithSameTimeSpec.

@Test
public void testWithSameTimeSpec() {
    TimeGranularitySpec spec = new TimeGranularitySpec(LONG, 1, DAYS, "1day");
    DefaultTimeConverter timeConverter = new DefaultTimeConverter();
    timeConverter.init(spec, spec);
    for (int i = 0; i < 1000; ++i) {
        Object convertedValue = timeConverter.convert(i);
        Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
        Assert.assertEquals(((Long) convertedValue).intValue(), i);
    }
    for (long i = 0; i < 1000; ++i) {
        Object convertedValue = timeConverter.convert(i);
        Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
        Assert.assertEquals(((Long) convertedValue).longValue(), i);
    }
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Test(org.testng.annotations.Test)

Example 4 with TimeGranularitySpec

use of com.linkedin.pinot.common.data.TimeGranularitySpec in project pinot by linkedin.

the class DefaultTimeConverterTest method testSimpleDateFormat.

@Test
public void testSimpleDateFormat() {
    TimeGranularitySpec incoming;
    TimeGranularitySpec outgoing;
    DefaultTimeConverter timeConverter;
    String SDF_PREFIX = TimeFormat.SIMPLE_DATE_FORMAT.toString();
    //this should not throw exception, since incoming == outgoing
    try {
        incoming = new TimeGranularitySpec(STRING, 1, HOURS, SDF_PREFIX + ":yyyyMMdd", "1hour");
        outgoing = new TimeGranularitySpec(STRING, 1, HOURS, SDF_PREFIX + ":yyyyMMdd", "1hour");
        timeConverter = new DefaultTimeConverter();
        timeConverter.init(incoming, outgoing);
    } catch (Exception e) {
        Assert.fail("sdf to sdf must be supported as long as incoming sdf = outgoing sdf");
    }
    //we don't support epoch to sdf conversion
    try {
        incoming = new TimeGranularitySpec(STRING, 1, HOURS, SDF_PREFIX + ":yyyyMMdd", "1hour");
        outgoing = new TimeGranularitySpec(LONG, 1, HOURS, "1hour");
        timeConverter = new DefaultTimeConverter();
        timeConverter.init(incoming, outgoing);
        Assert.fail("We don't support converting epoch to sdf currently");
    } catch (Exception e) {
    //expected
    }
    //we don't support sdf to epoch conversion
    try {
        incoming = new TimeGranularitySpec(STRING, 1, HOURS, SDF_PREFIX + ":yyyyMMdd", "1hour");
        outgoing = new TimeGranularitySpec(LONG, 1, HOURS, "1hour");
        timeConverter = new DefaultTimeConverter();
        timeConverter.init(incoming, outgoing);
        Assert.fail("We don't support converting sdf to epoch currently");
    } catch (Exception e) {
    //expected
    }
    //we don't support sdf to sdf conversion where incoming sdf != outoging sdf
    try {
        incoming = new TimeGranularitySpec(STRING, 1, HOURS, SDF_PREFIX + ":yyyyMMdd", "1hour");
        outgoing = new TimeGranularitySpec(STRING, 1, HOURS, SDF_PREFIX + ":yyyyMMddHH", "1hour");
        timeConverter = new DefaultTimeConverter();
        timeConverter.init(incoming, outgoing);
        Assert.fail("We don't support converting sdf to sdf where incoming sdf != outgoing sdf");
    } catch (Exception e) {
    //expected
    }
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Test(org.testng.annotations.Test)

Example 5 with TimeGranularitySpec

use of com.linkedin.pinot.common.data.TimeGranularitySpec in project pinot by linkedin.

the class PlainFieldExtractor method initTimeConverters.

private void initTimeConverters() {
    TimeFieldSpec timeFieldSpec = _schema.getTimeFieldSpec();
    if (timeFieldSpec != null) {
        TimeGranularitySpec incomingGranularitySpec = timeFieldSpec.getIncomingGranularitySpec();
        TimeGranularitySpec outgoingGranularitySpec = timeFieldSpec.getOutgoingGranularitySpec();
        _outgoingTimeColumnName = outgoingGranularitySpec.getName();
        if (!incomingGranularitySpec.equals(outgoingGranularitySpec)) {
            _incomingTimeColumnName = incomingGranularitySpec.getName();
            _timeConverter = TimeConverterProvider.getTimeConverter(incomingGranularitySpec, outgoingGranularitySpec);
        }
    }
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec)

Aggregations

TimeGranularitySpec (com.linkedin.pinot.common.data.TimeGranularitySpec)15 Test (org.testng.annotations.Test)8 TimeFieldSpec (com.linkedin.pinot.common.data.TimeFieldSpec)7 DimensionFieldSpec (com.linkedin.pinot.common.data.DimensionFieldSpec)6 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)6 MetricFieldSpec (com.linkedin.pinot.common.data.MetricFieldSpec)6 Schema (com.linkedin.pinot.common.data.Schema)5 FieldType (com.linkedin.pinot.common.data.FieldSpec.FieldType)2 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)1 ColumnMetadata (com.linkedin.pinot.core.segment.index.ColumnMetadata)1 CollectionSchema (com.linkedin.thirdeye.api.CollectionSchema)1 DimensionSpec (com.linkedin.thirdeye.api.DimensionSpec)1 MetricSpec (com.linkedin.thirdeye.api.MetricSpec)1 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)1 DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)1 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)1 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)1 DimensionSpec (com.linkedin.thirdeye.hadoop.config.DimensionSpec)1 MetricSpec (com.linkedin.thirdeye.hadoop.config.MetricSpec)1 FileInputStream (java.io.FileInputStream)1