diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/ExpressionConverter.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/ExpressionConverter.java index 7a7a0b887c1f5..a9dcfd4b5274c 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/ExpressionConverter.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/ExpressionConverter.java @@ -27,6 +27,8 @@ import com.facebook.presto.common.type.MapType; import com.facebook.presto.common.type.RealType; import com.facebook.presto.common.type.RowType; +import com.facebook.presto.common.type.TimeType; +import com.facebook.presto.common.type.TimestampType; import com.facebook.presto.common.type.Type; import com.facebook.presto.common.type.VarbinaryType; import com.facebook.presto.common.type.VarcharType; @@ -47,6 +49,7 @@ import static java.lang.Float.intBitsToFloat; import static java.lang.Math.toIntExact; import static java.util.Objects.requireNonNull; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.iceberg.expressions.Expressions.alwaysFalse; import static org.apache.iceberg.expressions.Expressions.alwaysTrue; import static org.apache.iceberg.expressions.Expressions.and; @@ -179,6 +182,10 @@ private static Object getIcebergLiteralValue(Type type, Marker marker) return toIntExact(((Long) marker.getValue())); } + if (type instanceof TimestampType || type instanceof TimeType) { + return MILLISECONDS.toMicros((Long) marker.getValue()); + } + if (type instanceof VarcharType) { return ((Slice) marker.getValue()).toStringUtf8(); } diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSource.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSource.java index bfed7659b48f7..f7a1ca9a35f9d 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSource.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSource.java @@ -42,6 +42,8 @@ import static com.facebook.presto.common.type.DoubleType.DOUBLE; import static com.facebook.presto.common.type.IntegerType.INTEGER; import static com.facebook.presto.common.type.RealType.REAL; +import static com.facebook.presto.common.type.TimeType.TIME; +import static com.facebook.presto.common.type.TimestampType.TIMESTAMP; import static com.facebook.presto.iceberg.IcebergErrorCode.ICEBERG_BAD_DATA; import static com.facebook.presto.iceberg.IcebergErrorCode.ICEBERG_INVALID_PARTITION_VALUE; import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; @@ -208,7 +210,7 @@ private static Object deserializePartitionValue(Type type, String valueString, S if (type.equals(DOUBLE)) { return parseDouble(valueString); } - if (type.equals(DATE)) { + if (type.equals(DATE) || type.equals(TIME) || type.equals(TIMESTAMP)) { return parseLong(valueString); } if (type instanceof VarcharType) { diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/TypeConverter.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/TypeConverter.java index 8058b224f49b4..360219ed22bad 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/TypeConverter.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/TypeConverter.java @@ -60,7 +60,6 @@ import static com.facebook.presto.common.type.RealType.REAL; import static com.facebook.presto.common.type.SmallintType.SMALLINT; import static com.facebook.presto.common.type.TimestampType.TIMESTAMP; -import static com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; import static com.facebook.presto.common.type.TinyintType.TINYINT; import static com.facebook.presto.common.type.VarbinaryType.VARBINARY; import static com.facebook.presto.hive.HiveType.HIVE_BINARY; @@ -116,6 +115,10 @@ public static Type toPrestoType(org.apache.iceberg.types.Type type, TypeManager return RealType.REAL; case INTEGER: return IntegerType.INTEGER; + case TIME: + return TimeType.TIME; + case TIMESTAMP: + return TimestampType.TIMESTAMP; case STRING: return VarcharType.createUnboundedVarcharType(); case LIST: @@ -175,13 +178,13 @@ public static org.apache.iceberg.types.Type toIcebergType(Type type) return fromMap((MapType) type); } if (type instanceof TimeType) { - throw new PrestoException(NOT_SUPPORTED, format("Time not supported for Iceberg.")); + return Types.TimeType.get(); } if (type instanceof TimestampType) { - throw new PrestoException(NOT_SUPPORTED, format("Timestamp not supported for Iceberg.")); + return Types.TimestampType.withoutZone(); } if (type instanceof TimestampWithTimeZoneType) { - throw new PrestoException(NOT_SUPPORTED, format("Timestamp with timezone not supported for Iceberg.")); + return Types.TimestampType.withZone(); } throw new PrestoException(NOT_SUPPORTED, "Type not supported for Iceberg: " + type.getDisplayName()); } @@ -268,10 +271,6 @@ private static TypeInfo toHiveTypeInfo(Type type) if (TIMESTAMP.equals(type)) { return HIVE_TIMESTAMP.getTypeInfo(); } - if (TIMESTAMP_WITH_TIME_ZONE.equals(type)) { - // Hive does not have TIMESTAMP_WITH_TIME_ZONE, this is just a work around for iceberg. - return HIVE_TIMESTAMP.getTypeInfo(); - } if (type instanceof DecimalType) { DecimalType decimalType = (DecimalType) type; return new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()); diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergSmoke.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergSmoke.java index 57bbc9c35cc14..88a26b476e9f2 100644 --- a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergSmoke.java +++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergSmoke.java @@ -53,7 +53,10 @@ protected QueryRunner createQueryRunner() @Test public void testTimestamp() { - // TODO + assertUpdate("CREATE TABLE test_timestamp (x timestamp)"); + assertUpdate("INSERT INTO test_timestamp VALUES (timestamp '2017-05-01 10:12:34')", 1); + assertQuery("SELECT * FROM test_timestamp", "SELECT CAST('2017-05-01 10:12:34' AS TIMESTAMP)"); + dropTable(getSession(), "test_timestamp"); } @Test