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