deniskuzZ commented on code in PR #5645:
URL: https://github.com/apache/hive/pull/5645#discussion_r1965175054
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergFilterFactory.java:
##########
@@ -155,6 +206,92 @@ private static Object leafToLiteral(PredicateLeaf leaf) {
}
}
+ private static Object getTransformedLiteral(Object literal, TransformSpec
transform) {
+ if (transform == null) {
+ return literal;
+ }
+ try {
+ switch (transform.getTransformType()) {
+ case YEAR:
+ return parseYearToTransformYear(literal.toString());
+ case MONTH:
+ return parseMonthToTransformMonth(literal.toString());
+ case DAY:
+ return parseDayToTransformMonth(literal.toString());
+ case HOUR:
+ return parseHourToTransformHour(literal.toString());
+ case TRUNCATE:
+ return
Transforms.truncate(transform.getTransformParam().get()).bind(Types.StringType.get())
+ .apply(literal.toString());
+ case BUCKET:
+ return
Transforms.bucket(transform.getTransformParam().get()).bind(Types.StringType.get())
+ .apply(literal.toString());
+ case IDENTITY:
+ return literal;
+ default:
+ throw new UnsupportedOperationException("Unknown transform: " +
transform.getTransformType());
+ }
+ } catch (NumberFormatException | DateTimeException | IllegalStateException
e) {
+ throw new RuntimeException(
+ String.format("Unable to parse value '%s' as '%s' transform value",
literal.toString(), transform));
+ }
+ }
+
+ private static final int ICEBERG_EPOCH_YEAR = 1970;
+ private static final int ICEBERG_EPOCH_MONTH = 1;
+
+ /**
+ * In the partition path years are represented naturally, e.g. 1984.
However, we need
+ * to convert it to an integer which represents the years from 1970. So, for
1984 the
+ * return value should be 14.
+ */
+ private static Integer parseYearToTransformYear(String yearStr) {
+ int year = Integer.parseInt(yearStr);
+ return year - ICEBERG_EPOCH_YEAR;
+ }
+
+ /**
+ * In the partition path months are represented as year-month, e.g. 2021-01.
We
+ * need to convert it to a single integer which represents the months from
'1970-01'.
+ */
+ private static Integer parseMonthToTransformMonth(String monthStr) {
+ String[] parts = monthStr.split("-", -1);
+ Preconditions.checkState(parts.length == 2);
+ int year = Integer.parseInt(parts[0]);
+ int month = Integer.parseInt(parts[1]);
+ int years = year - ICEBERG_EPOCH_YEAR;
+ int months = month - ICEBERG_EPOCH_MONTH;
+ return years * 12 + months;
+ }
+
+ /**
+ * In the partition path days are represented as year-month-day, e.g.
2023-12-12.
+ * This functions converts this string to an integer which represents the
days from
+ * '1970-01-01' with the help of Iceberg's type converter.
+ */
+ private static Integer parseDayToTransformMonth(String monthStr) {
Review Comment:
DateTimeUtil#daysToMonths?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]