rdblue commented on code in PR #5601:
URL: https://github.com/apache/iceberg/pull/5601#discussion_r961850097


##########
api/src/main/java/org/apache/iceberg/transforms/Dates.java:
##########
@@ -27,44 +27,67 @@
 import org.apache.iceberg.expressions.Expression;
 import org.apache.iceberg.expressions.Expressions;
 import org.apache.iceberg.expressions.UnboundPredicate;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
 import org.apache.iceberg.types.Type;
 import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.SerializableFunction;
 
 enum Dates implements Transform<Integer, Integer> {
   YEAR(ChronoUnit.YEARS, "year"),
   MONTH(ChronoUnit.MONTHS, "month"),
   DAY(ChronoUnit.DAYS, "day");
 
+  static class Apply implements SerializableFunction<Integer, Integer> {
+    private final ChronoUnit granularity;
+
+    Apply(ChronoUnit granularity) {
+      this.granularity = granularity;
+    }
+
+    @Override
+    public Integer apply(Integer days) {
+      if (days == null) {
+        return null;
+      }
+
+      if (granularity == ChronoUnit.DAYS) {
+        return days;
+      }
+
+      if (days >= 0) {
+        LocalDate date = EPOCH.plusDays(days);
+        return (int) granularity.between(EPOCH, date);
+      } else {
+        // add 1 day to the value to account for the case where there is 
exactly 1 unit between the
+        // date and epoch
+        // because the result will always be decremented.

Review Comment:
   Fixed. I'll have to watch out for this. I think it was introduced by 
auto-formatting.



##########
api/src/main/java/org/apache/iceberg/transforms/Months.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.transforms;
+
+import java.io.ObjectStreamException;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+
+public class Months<T> extends TimeTransform<T> {
+  private static final Months<?> INSTANCE = new Months<>();
+
+  @SuppressWarnings("unchecked")
+  static <T> Months<T> get() {
+    return (Months<T>) INSTANCE;
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  protected Transform<T, Integer> toEnum(Type type) {
+    switch (type.typeId()) {
+      case DATE:
+        return (Transform<T, Integer>) Dates.MONTH;
+      case TIMESTAMP:
+        return (Transform<T, Integer>) Timestamps.MONTH;
+    }
+    throw new IllegalArgumentException("Unsupported type: " + type);

Review Comment:
   Fixed. Also fixed the one in `Years`.



-- 
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]

Reply via email to