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