[bugfix](iceberg)Read error when timestamp does not have time zone for 2.1 (#36435)

bp: #36141
This commit is contained in:
wuwenchi
2024-06-20 18:32:31 +08:00
committed by GitHub
parent 22d37ba3fe
commit ac0f6e75d2
9 changed files with 69 additions and 16 deletions

View File

@ -53,7 +53,7 @@ import java.util.regex.Pattern;
// TODO(dhc) add nanosecond timer for coordinator's root profile
public class TimeUtils {
public static final String UTC_TIME_ZONE = "Europe/London"; // This is just a Country to represent UTC offset +00:00
public static final String UTC_TIME_ZONE = "UTC"; // This is just a Country to represent UTC offset +00:00
public static final String DEFAULT_TIME_ZONE = "Asia/Shanghai";
public static final ZoneId TIME_ZONE;
public static final ImmutableMap<String, String> timeZoneAliasMap;
@ -148,6 +148,10 @@ public class TimeUtils {
return TimeZone.getTimeZone(ZoneId.of(timezone, timeZoneAliasMap));
}
public static TimeZone getUTCTimeZone() {
return TimeZone.getTimeZone(UTC_TIME_ZONE);
}
// return the time zone of current system
public static TimeZone getSystemTimeZone() {
return TimeZone.getTimeZone(ZoneId.of(ZoneId.systemDefault().getId(), timeZoneAliasMap));

View File

@ -319,7 +319,11 @@ public class IcebergUtils {
case DATE:
return dateLiteral.getStringValue();
case TIMESTAMP:
return dateLiteral.getUnixTimestampWithMicroseconds(TimeUtils.getTimeZone());
if (((Types.TimestampType) icebergType).shouldAdjustToUTC()) {
return dateLiteral.getUnixTimestampWithMicroseconds(TimeUtils.getTimeZone());
} else {
return dateLiteral.getUnixTimestampWithMicroseconds(TimeUtils.getUTCTimeZone());
}
default:
return null;
}