use of org.apache.pinot.spi.data.TimeFieldSpec in project presto by prestodb.
the class PinotColumnUtils method getPrestoTypeFromPinotType.
public static Type getPrestoTypeFromPinotType(FieldSpec field, boolean inferDateType, boolean inferTimestampType) {
if (field.isSingleValueField()) {
switch(field.getFieldType()) {
case TIME:
TimeFieldSpec timeFieldSpec = (TimeFieldSpec) field;
TimeGranularitySpec outSpec = timeFieldSpec.getOutgoingGranularitySpec();
if (outSpec != null) {
if (outSpec.getTimeFormat().equalsIgnoreCase(EPOCH.name())) {
if (inferDateType && (DAYS == outSpec.getTimeType()) && (outSpec.getTimeUnitSize() == 1)) {
return DateType.DATE;
}
if (inferTimestampType && (MILLISECONDS == outSpec.getTimeType()) && (outSpec.getTimeUnitSize() == 1)) {
return TimestampType.TIMESTAMP;
}
}
} else {
TimeGranularitySpec inSpec = timeFieldSpec.getIncomingGranularitySpec();
if (inferDateType && (DAYS == inSpec.getTimeType()) && (inSpec.getTimeUnitSize() == 1)) {
return DateType.DATE;
}
if (inferTimestampType && (MILLISECONDS == inSpec.getTimeType()) && (inSpec.getTimeUnitSize() == 1)) {
return TimestampType.TIMESTAMP;
}
}
return getPrestoTypeFromPinotType(field.getDataType());
case DATE_TIME:
DateTimeFieldSpec dateTimeFieldSpec = (DateTimeFieldSpec) field;
if (inferDateType && dateTimeFieldSpec.getFormat().equalsIgnoreCase(DAYS_SINCE_EPOCH_TIME_FORMAT)) {
return DateType.DATE;
}
if (inferTimestampType && dateTimeFieldSpec.getFormat().equalsIgnoreCase(MILLISECONDS_SINCE_EPOCH_TIME_FORMAT)) {
return TimestampType.TIMESTAMP;
}
}
return getPrestoTypeFromPinotType(field.getDataType());
}
return new ArrayType(getPrestoTypeFromPinotType(field.getDataType()));
}
Aggregations