Search in sources :

Example 6 with TimeGranularitySpec

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

the class PinotSegmentRecordReaderTest method createPinotSchema.

private Schema createPinotSchema() {
    Schema testSchema = new Schema();
    testSchema.setSchemaName("schema");
    FieldSpec spec;
    spec = new DimensionFieldSpec(D_SV_1, DataType.STRING, true);
    testSchema.addField(spec);
    spec = new DimensionFieldSpec(D_MV_1, DataType.STRING, false);
    testSchema.addField(spec);
    spec = new MetricFieldSpec(M1, DataType.INT);
    testSchema.addField(spec);
    spec = new MetricFieldSpec(M2, DataType.FLOAT);
    testSchema.addField(spec);
    spec = new TimeFieldSpec(new TimeGranularitySpec(DataType.LONG, TimeUnit.HOURS, TIME));
    testSchema.addField(spec);
    return testSchema;
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Schema(com.linkedin.pinot.common.data.Schema) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec)

Example 7 with TimeGranularitySpec

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

the class DefaultTimeConverterTest method testWithDifferentTimeSpecs.

@Test
public void testWithDifferentTimeSpecs() {
    TimeGranularitySpec incoming = new TimeGranularitySpec(LONG, 2, DAYS, "2days");
    TimeGranularitySpec outgoing = new TimeGranularitySpec(LONG, 24, HOURS, "24hours");
    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 * 2);
    }
    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 * 2);
    }
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Test(org.testng.annotations.Test)

Example 8 with TimeGranularitySpec

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

the class DefaultTimeConverterTest method testWithDifferentIncomingValueTypes.

@Test
public void testWithDifferentIncomingValueTypes() {
    TimeGranularitySpec incoming = new TimeGranularitySpec(LONG, 2, DAYS, "2days");
    TimeGranularitySpec outgoing = new TimeGranularitySpec(LONG, 24, HOURS, "24hours");
    DefaultTimeConverter timeConverter = new DefaultTimeConverter();
    timeConverter.init(incoming, outgoing);
    Object convertedValue = timeConverter.convert("1");
    Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
    Assert.assertEquals(((Long) convertedValue).intValue(), 2);
    convertedValue = timeConverter.convert(1);
    Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
    Assert.assertEquals(((Long) convertedValue).intValue(), 2);
    convertedValue = timeConverter.convert((long) 1);
    Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
    Assert.assertEquals(((Long) convertedValue).intValue(), 2);
    convertedValue = timeConverter.convert((short) 1);
    Assert.assertTrue(convertedValue instanceof Long, "Converted value data type should be Long");
    Assert.assertEquals(((Long) convertedValue).intValue(), 2);
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Test(org.testng.annotations.Test)

Example 9 with TimeGranularitySpec

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

the class DefaultTimeConverterTest method testWithOutgoingValueTypesString.

@Test
public void testWithOutgoingValueTypesString() {
    TimeGranularitySpec incoming = new TimeGranularitySpec(LONG, 2, DAYS, "2days");
    TimeGranularitySpec outgoing = new TimeGranularitySpec(STRING, 24, HOURS, "24hours");
    DefaultTimeConverter timeConverter = new DefaultTimeConverter();
    timeConverter.init(incoming, outgoing);
    Object convertedValue = timeConverter.convert("1");
    Assert.assertTrue(convertedValue instanceof String, "Converted value data type should be STRING");
    Assert.assertEquals(Integer.parseInt(convertedValue.toString()), 2);
    Assert.assertEquals(convertedValue, "2");
    convertedValue = timeConverter.convert(1);
    Assert.assertTrue(convertedValue instanceof String, "Converted value data type should be STRING");
    Assert.assertEquals(Integer.parseInt(convertedValue.toString()), 2);
    Assert.assertEquals(convertedValue, "2");
    convertedValue = timeConverter.convert((long) 1);
    Assert.assertTrue(convertedValue instanceof String, "Converted value data type should be STRING");
    Assert.assertEquals(Integer.parseInt(convertedValue.toString()), 2);
    Assert.assertEquals(convertedValue, "2");
    convertedValue = timeConverter.convert((short) 1);
    Assert.assertTrue(convertedValue instanceof String, "Converted value data type should be STRING");
    Assert.assertEquals(Integer.parseInt(convertedValue.toString()), 2);
    Assert.assertEquals(convertedValue, "2");
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Test(org.testng.annotations.Test)

Example 10 with TimeGranularitySpec

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

the class ConfigGenerator method generateDatasetConfig.

public static DatasetConfigDTO generateDatasetConfig(String dataset, Schema schema) {
    List<String> dimensions = schema.getDimensionNames();
    TimeGranularitySpec timeSpec = schema.getTimeFieldSpec().getOutgoingGranularitySpec();
    // Create DatasetConfig
    DatasetConfigDTO datasetConfigDTO = new DatasetConfigDTO();
    datasetConfigDTO.setDataset(dataset);
    datasetConfigDTO.setDimensions(dimensions);
    datasetConfigDTO.setTimeColumn(timeSpec.getName());
    datasetConfigDTO.setTimeDuration(timeSpec.getTimeUnitSize());
    datasetConfigDTO.setTimeUnit(timeSpec.getTimeType());
    datasetConfigDTO.setTimeFormat(timeSpec.getTimeFormat());
    if (timeSpec.getTimeFormat().startsWith(TimeFormat.SIMPLE_DATE_FORMAT.toString())) {
        datasetConfigDTO.setTimezone(PDT_TIMEZONE);
    }
    return datasetConfigDTO;
}
Also used : TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)

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