dshogan-amzn commented on code in PR #18933:
URL: https://github.com/apache/iceberg/pull/18933#discussion_r4614881439


##########
api/src/test/java/org/apache/iceberg/expressions/TestInclusiveMetricsEvaluatorWithPartitionSpec.java:
##########
@@ -0,0 +1,237 @@
+/*
+ * 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.expressions;
+
+import static org.apache.iceberg.expressions.Expressions.and;
+import static org.apache.iceberg.expressions.Expressions.in;
+import static org.apache.iceberg.expressions.Expressions.notIn;
+import static org.apache.iceberg.types.Conversions.toByteBuffer;
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.List;
+import java.util.function.Function;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.TestHelpers.Row;
+import org.apache.iceberg.TestHelpers.TestDataFile;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.transforms.Transforms;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.types.Types.IntegerType;
+import org.junit.jupiter.api.Test;
+
+public class TestInclusiveMetricsEvaluatorWithPartitionSpec {
+  private static final Schema SCHEMA =
+      new Schema(required(1, "id", IntegerType.get()), optional(2, "data", 
Types.StringType.get()));
+  private static final int BUCKETS = 16;
+  private static final Function<Integer, Integer> BUCKET =
+      Transforms.<Integer>bucket(BUCKETS).bind(IntegerType.get());
+
+  /**
+   * Id bounds drawn from one bucket, a value from that bucket outside the 
bounds, and a value from
+   * another bucket inside the bounds.
+   */
+  private record BucketCase(int bucket, int lower, int upper, int ownValue, 
int foreignValue) {}
+
+  private static BucketCase bucketCase() {
+    int bucket = BUCKET.apply(100);
+    List<Integer> values = Lists.newArrayList();
+    for (int value = 0; values.size() < 7; value += 1) {
+      if (BUCKET.apply(value) == bucket) {
+        values.add(value);
+      }
+    }
+
+    int lower = values.get(0);
+    int upper = values.get(5);
+    int foreignValue = lower + 1;
+    while (BUCKET.apply(foreignValue) == bucket) {
+      foreignValue += 1;
+    }
+    assertThat(foreignValue).isLessThan(upper);
+
+    return new BucketCase(bucket, lower, upper, values.get(6), foreignValue);
+  }
+
+  private static DataFile fileWithIdBounds(StructLike partition, int lower, 
int upper) {
+    return new TestDataFile(
+        "file.parquet",
+        partition,
+        10,
+        ImmutableMap.of(1, 10L),
+        ImmutableMap.of(1, 0L),
+        null,
+        ImmutableMap.of(1, toByteBuffer(IntegerType.get(), lower)),
+        ImmutableMap.of(1, toByteBuffer(IntegerType.get(), upper)));
+  }
+
+  private static boolean schemaOnly(Expression expr, DataFile file) {
+    return new InclusiveMetricsEvaluator(SCHEMA, expr).eval(file);
+  }
+
+  private static boolean partitionAware(PartitionSpec spec, Expression expr, 
DataFile file) {
+    return InclusiveMetricsEvaluator.forRowFilter(expr, spec, true).eval(file);
+  }
+
+  @Test
+  public void testBucketInUsesLiteralsForFilePartition() {

Review Comment:
   Added both:
   
   - testBucketInNarrowsBeforeInPredicateLimit: 201 literals narrowed to 200 
are evaluated and the file is pruned; 202 narrowed to 201 keep the existing 
conservative behavior; a literal from the file's bucket inside the bounds keeps 
the file.
   - testBucketInOnStringColumn: bucket narrowing on a STRING source.



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