use of com.linkedin.thirdeye.api.CollectionSchema 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;
}
Aggregations