Skip to content

Commit

Permalink
Fix timestamp with timezone mapping in iceberg type converter
Browse files Browse the repository at this point in the history
  • Loading branch information
auden-woolfson committed Aug 27, 2024
1 parent 581eb87 commit 38919d7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public static Type toPrestoType(org.apache.iceberg.types.Type type, TypeManager
case TIME:
return TimeType.TIME;
case TIMESTAMP:
Types.TimestampType timestampType = (Types.TimestampType) type.asPrimitiveType();
if (timestampType.shouldAdjustToUTC()) {
return TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
}
return TimestampType.TIMESTAMP;
case STRING:
return VarcharType.createUnboundedVarcharType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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.TimestampType.TIMESTAMP;
import static com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
import static com.facebook.presto.common.type.VarbinaryType.VARBINARY;
import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
import static com.facebook.presto.iceberg.NestedFieldConverter.toIcebergNestedField;
Expand Down Expand Up @@ -176,6 +178,12 @@ protected static PrestoIcebergNestedField prestoIcebergNestedField(
case "date":
prestoType = DATE;
break;
case "timestamp":
prestoType = TIMESTAMP;
break;
case "timestamptz":
prestoType = TIMESTAMP_WITH_TIME_ZONE;
break;
case "nested":
prestoType = RowType.from(ImmutableList.of(
RowType.field("int", INTEGER),
Expand Down Expand Up @@ -239,6 +247,12 @@ protected static Types.NestedField nestedField(int id, String name)
case "date":
icebergType = Types.DateType.get();
break;
case "timestamp":
icebergType = Types.TimestampType.withoutZone();
break;
case "timestamptz":
icebergType = Types.TimestampType.withZone();
break;
case "nested":
icebergType = nested();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ protected static PrestoIcebergSchema prestoIcebergSchema(TypeManager typeManager
prestoIcebergNestedField(9, "varchar", typeManager),
prestoIcebergNestedField(10, "varbinary", typeManager),
prestoIcebergNestedField(11, "row", typeManager),
prestoIcebergNestedField(12, "date", typeManager)));
prestoIcebergNestedField(12, "date", typeManager),
prestoIcebergNestedField(13, "timestamp", typeManager),
prestoIcebergNestedField(14, "timestamptz", typeManager)));

Map<String, Integer> columnNameToIdMapping = getColumnNameToIdMapping();

Expand All @@ -114,11 +116,13 @@ private static Map<String, Integer> getColumnNameToIdMapping()
columnNameToIdMapping.put("varbinary", 10);
columnNameToIdMapping.put("row", 11);
columnNameToIdMapping.put("date", 12);
columnNameToIdMapping.put("array.element", 13);
columnNameToIdMapping.put("map.key", 14);
columnNameToIdMapping.put("map.value", 15);
columnNameToIdMapping.put("row.int", 16);
columnNameToIdMapping.put("row.varchar", 17);
columnNameToIdMapping.put("timestamp", 13);
columnNameToIdMapping.put("timestamptz", 14);
columnNameToIdMapping.put("array.element", 15);
columnNameToIdMapping.put("map.key", 16);
columnNameToIdMapping.put("map.value", 17);
columnNameToIdMapping.put("row.int", 18);
columnNameToIdMapping.put("row.varchar", 19);

return columnNameToIdMapping;
}
Expand All @@ -137,7 +141,9 @@ protected static Schema schema()
nestedField(9, "varchar"),
nestedField(10, "varbinary"),
nestedField(11, "row"),
nestedField(12, "date")));
nestedField(12, "date"),
nestedField(13, "timestamp"),
nestedField(14, "timestamptz")));

Type schemaAsStruct = Types.StructType.of(fields);
AtomicInteger nextFieldId = new AtomicInteger(1);
Expand Down

0 comments on commit 38919d7

Please sign in to comment.