|
43 | 43 | import java.io.IOException;
|
44 | 44 | import java.math.BigDecimal;
|
45 | 45 | import java.math.RoundingMode;
|
| 46 | +import java.time.LocalDate; |
46 | 47 | import java.time.ZoneOffset;
|
47 | 48 | import java.time.ZonedDateTime;
|
48 | 49 | import java.time.format.DateTimeFormatter;
|
|
62 | 63 |
|
63 | 64 | import static com.google.common.base.Preconditions.checkArgument;
|
64 | 65 | import static com.google.common.collect.ImmutableList.toImmutableList;
|
65 |
| -import static io.trino.hive.formats.HiveFormatUtils.parseHiveDate; |
| 66 | +import static io.trino.hive.formats.HiveFormatUtils.DATE_PARSER; |
66 | 67 | import static io.trino.hive.formats.HiveFormatUtils.parseHiveTimestamp;
|
67 | 68 | import static io.trino.hive.formats.HiveFormatUtils.scaleDecimal;
|
68 | 69 | import static io.trino.hive.formats.line.openxjson.JsonWriter.canonicalizeJsonString;
|
@@ -899,6 +900,32 @@ public static long parseDecimalHexOctalLong(String stringValue)
|
899 | 900 | return Long.parseLong(stringValue);
|
900 | 901 | }
|
901 | 902 |
|
| 903 | + /* |
| 904 | + * The parseHiveDate method in HiveFormatUtils.java that the native OpenX reader was using only supported |
| 905 | + * a space delimiter to remove any characters after 'yyyy-mm-dd'. As a result, while '2025-01-04 00:00:00.000Z' |
| 906 | + * was correctly parsed as '2025-01-04', strings like '2025-01-04T00:00:00.000Z' or '2025-01-04AA00:00:00.000Z' |
| 907 | + * were throwing exceptions and being parsed as null. |
| 908 | + * This new parseHiveDate method removes any characters after 'yyyy-mm-dd', regardless of the delimiter. |
| 909 | + */ |
| 910 | + private static LocalDate parseHiveDate(String value) |
| 911 | + { |
| 912 | + value = value.trim(); |
| 913 | + int length = value.length(); |
| 914 | + int endIndex = length; |
| 915 | + |
| 916 | + // Find the first character that isn't a digit or hyphen |
| 917 | + for (int i = 0; i < length; i++) { |
| 918 | + char c = value.charAt(i); |
| 919 | + if (c != '-' && (c < '0' || c > '9')) { |
| 920 | + endIndex = i; |
| 921 | + break; |
| 922 | + } |
| 923 | + } |
| 924 | + |
| 925 | + String datePortion = value.substring(0, endIndex); |
| 926 | + return LocalDate.parse(datePortion, DATE_PARSER); |
| 927 | + } |
| 928 | + |
902 | 929 | private static boolean isHex(String s)
|
903 | 930 | {
|
904 | 931 | // This does not allow for `0x-123`
|
|
0 commit comments