nastra commented on code in PR #13217: URL: https://github.com/apache/iceberg/pull/13217#discussion_r2166344149
########## api/src/main/java/org/apache/iceberg/transforms/Timestamps.java: ########## @@ -32,24 +32,79 @@ import org.apache.iceberg.util.SerializableFunction; enum Timestamps implements Transform<Long, Integer> { - MICROS_TO_YEAR(ChronoUnit.YEARS, "year", MicrosToYears.INSTANCE), - MICROS_TO_MONTH(ChronoUnit.MONTHS, "month", MicrosToMonths.INSTANCE), - MICROS_TO_DAY(ChronoUnit.DAYS, "day", MicrosToDays.INSTANCE), - MICROS_TO_HOUR(ChronoUnit.HOURS, "hour", MicrosToHours.INSTANCE), + MICROS_TO_YEAR(ChronoUnit.YEARS, "year", TimestampUnit.MICROS), + MICROS_TO_MONTH(ChronoUnit.MONTHS, "month", TimestampUnit.MICROS), + MICROS_TO_DAY(ChronoUnit.DAYS, "day", TimestampUnit.MICROS), + MICROS_TO_HOUR(ChronoUnit.HOURS, "hour", TimestampUnit.MICROS), - NANOS_TO_YEAR(ChronoUnit.YEARS, "year", NanosToYears.INSTANCE), - NANOS_TO_MONTH(ChronoUnit.MONTHS, "month", NanosToMonths.INSTANCE), - NANOS_TO_DAY(ChronoUnit.DAYS, "day", NanosToDays.INSTANCE), - NANOS_TO_HOUR(ChronoUnit.HOURS, "hour", NanosToHours.INSTANCE); + NANOS_TO_YEAR(ChronoUnit.YEARS, "year", TimestampUnit.NANOS), + NANOS_TO_MONTH(ChronoUnit.MONTHS, "month", TimestampUnit.NANOS), + NANOS_TO_DAY(ChronoUnit.DAYS, "day", TimestampUnit.NANOS), + NANOS_TO_HOUR(ChronoUnit.HOURS, "hour", TimestampUnit.NANOS); + + @Immutable + static class Apply implements SerializableFunction<Long, Integer> { + private final ChronoUnit granularity; + private final TimestampUnit timestampUnit; + + Apply(ChronoUnit granularity, TimestampUnit timestampUnit) { + this.granularity = granularity; + this.timestampUnit = timestampUnit; + } + + @Override + public Integer apply(Long timestamp) { + if (timestamp == null) { + return null; + } + + switch (timestampUnit) { + case MICROS: + switch (granularity) { + case YEARS: + return DateTimeUtil.microsToYears(timestamp); + case MONTHS: + return DateTimeUtil.microsToMonths(timestamp); + case DAYS: + return DateTimeUtil.microsToDays(timestamp); + case HOURS: + return DateTimeUtil.microsToHours(timestamp); + default: + throw new UnsupportedOperationException("Unsupported time unit: " + granularity); + } + Review Comment: ```suggestion ``` -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org