Search in sources :

Example 1 with TimeFieldSpec

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()));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) TimeGranularitySpec(org.apache.pinot.spi.data.TimeGranularitySpec) TimeFieldSpec(org.apache.pinot.spi.data.TimeFieldSpec) DateTimeFieldSpec(org.apache.pinot.spi.data.DateTimeFieldSpec) DateTimeFieldSpec(org.apache.pinot.spi.data.DateTimeFieldSpec)

Aggregations

ArrayType (com.facebook.presto.common.type.ArrayType)1 DateTimeFieldSpec (org.apache.pinot.spi.data.DateTimeFieldSpec)1 TimeFieldSpec (org.apache.pinot.spi.data.TimeFieldSpec)1 TimeGranularitySpec (org.apache.pinot.spi.data.TimeGranularitySpec)1