|
17 | 17 | */
|
18 | 18 | package org.apache.hadoop.hive.serde2.avro;
|
19 | 19 |
|
| 20 | +import java.time.Instant; |
| 21 | +import java.time.LocalDateTime; |
20 | 22 | import java.time.ZoneOffset;
|
21 | 23 | import java.util.LinkedHashMap;
|
22 | 24 | import java.util.List;
|
23 | 25 | import java.util.Map;
|
24 | 26 | import java.util.Set;
|
25 | 27 | import java.util.TimeZone;
|
26 | 28 |
|
| 29 | +import org.apache.avro.LogicalType; |
27 | 30 | import org.apache.avro.Schema;
|
28 | 31 | import org.apache.avro.Schema.Field;
|
29 | 32 | import org.apache.avro.Schema.Type;
|
@@ -231,10 +234,18 @@ private Object serializePrimitive(TypeInfo typeInfo, PrimitiveObjectInspector fi
|
231 | 234 | case TIMESTAMP:
|
232 | 235 | Timestamp timestamp =
|
233 | 236 | ((TimestampObjectInspector) fieldOI).getPrimitiveJavaObject(structFieldData);
|
| 237 | + LogicalType logicalType = schema.getLogicalType(); |
| 238 | + if (logicalType != null && logicalType.getName().equals(AvroSerDe.TIMESTAMP_TYPE_NAME_MICROS)) { |
| 239 | + long micros = defaultProleptic ? timestamp.toEpochMicro() : |
| 240 | + CalendarUtils.convertTimeToProlepticMicros(timestamp.toEpochMicro()); |
| 241 | + timestamp = TimestampTZUtil.convertTimestampToZone( |
| 242 | + Timestamp.ofEpochMicro(micros), TimeZone.getDefault().toZoneId(), ZoneOffset.UTC, legacyConversion); |
| 243 | + return timestamp.toEpochMicro(); |
| 244 | + } |
234 | 245 | long millis = defaultProleptic ? timestamp.toEpochMilli() :
|
235 |
| - CalendarUtils.convertTimeToHybrid(timestamp.toEpochMilli()); |
| 246 | + CalendarUtils.convertTimeToHybrid(timestamp.toEpochMilli()); |
236 | 247 | timestamp = TimestampTZUtil.convertTimestampToZone(
|
237 |
| - Timestamp.ofEpochMilli(millis), TimeZone.getDefault().toZoneId(), ZoneOffset.UTC, legacyConversion); |
| 248 | + Timestamp.ofEpochMilli(millis), TimeZone.getDefault().toZoneId(), ZoneOffset.UTC, legacyConversion); |
238 | 249 | return timestamp.toEpochMilli();
|
239 | 250 | case UNKNOWN:
|
240 | 251 | throw new AvroSerdeException("Received UNKNOWN primitive category.");
|
|
0 commit comments