mhatipog commented on code in PR #19065:
URL: https://github.com/apache/iceberg/pull/19065#discussion_r4720535213
##########
orc/src/main/java/org/apache/iceberg/orc/ExpressionToSearchArgument.java:
##########
@@ -46,14 +49,46 @@ class ExpressionToSearchArgument
extends ExpressionVisitors.BoundVisitor<ExpressionToSearchArgument.Action>
{
static SearchArgument convert(Expression expr, TypeDescription readSchema) {
- Map<Integer, String> idToColumnName =
- ORCSchemaUtil.idToOrcName(ORCSchemaUtil.convert(readSchema));
+ Schema schema = ORCSchemaUtil.convert(readSchema);
+ Map<Integer, String> idToColumnName = ORCSchemaUtil.idToOrcName(schema);
SearchArgument.Builder builder = SearchArgumentFactory.newBuilder();
- ExpressionVisitors.visit(expr, new ExpressionToSearchArgument(builder,
idToColumnName))
+ ExpressionVisitors.visit(
+ expr,
Review Comment:
Done. The converter now applies `Expressions.rewriteNot` before visiting,
and `testNegatedNotNullOnFieldWithOptionalAncestor` writes a real ORC file with
a null parent and reads it back with both `isNull("parent.leaf")` and
`not(notNull("parent.leaf"))`.
##########
api/src/main/java/org/apache/iceberg/expressions/InclusiveMetricsEvaluator.java:
##########
@@ -96,9 +131,24 @@ private boolean eval(ContentFile<?> file) {
return ExpressionVisitors.visitEvaluator(expr, this);
}
+ private boolean hasSuspectLegacyOrcCounts(int id) {
+ if (fileFormat != FileFormat.ORC ||
!fieldsWithOptionalStructAncestor.contains(id)) {
Review Comment:
Good catch. A null `fileFormat` is now treated as possibly ORC, so the guard
stays on. `TestLegacyOrcManifestReader` covers it with a reader that selects
only `file_path`.
##########
api/src/main/java/org/apache/iceberg/expressions/InclusiveMetricsEvaluator.java:
##########
@@ -55,6 +61,31 @@ public InclusiveMetricsEvaluator(Schema schema, Expression
unbound) {
public InclusiveMetricsEvaluator(Schema schema, Expression unbound, boolean
caseSensitive) {
StructType struct = schema.asStruct();
this.expr = Binder.bind(struct, rewriteNot(unbound), caseSensitive);
+ this.fieldsWithOptionalStructAncestor =
fieldsWithOptionalStructAncestor(schema);
+ }
+
+ private static Set<Integer> fieldsWithOptionalStructAncestor(Schema schema) {
+ Map<Integer, Integer> parents = TypeUtil.indexParents(schema.asStruct());
+ Set<Integer> fields = new HashSet<>();
Review Comment:
Switched to `Sets.newHashSet()`. Spotless is clean now as well (the last
push fixes the formatting in the two test files).
##########
orc/src/main/java/org/apache/iceberg/orc/ExpressionToSearchArgument.java:
##########
@@ -46,14 +49,46 @@ class ExpressionToSearchArgument
extends ExpressionVisitors.BoundVisitor<ExpressionToSearchArgument.Action>
{
static SearchArgument convert(Expression expr, TypeDescription readSchema) {
- Map<Integer, String> idToColumnName =
- ORCSchemaUtil.idToOrcName(ORCSchemaUtil.convert(readSchema));
+ Schema schema = ORCSchemaUtil.convert(readSchema);
Review Comment:
Agreed. `convert` now takes the Iceberg schema from `OrcIterable` for
nullability and uses the projected ORC schema only for column names, so
required parents keep pruning. The existing tests also run through
`buildOrcProjection` now.
##########
core/src/test/java/org/apache/iceberg/TestLegacyOrcManifestReader.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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 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;
+
+import static org.apache.iceberg.expressions.Expressions.isNull;
+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 java.io.IOException;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.relocated.com.google.common.collect.Streams;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.TestTemplate;
+
+public class TestLegacyOrcManifestReader extends TestBase {
+ @TestTemplate
+ public void testPreviouslyWrittenOrcManifestRemainsReadable() throws
IOException {
+ Schema schema =
+ new Schema(
+ required(1, "id", Types.IntegerType.get()),
+ optional(2, "parent", Types.StructType.of(optional(3, "leaf",
Types.IntegerType.get()))));
+ PartitionSpec spec = PartitionSpec.builderFor(schema).build();
+
+ // This is the metadata emitted by the pre-fix ORC metrics conversion for
a file with
+ // two rows: parent = NULL, and parent = {leaf: 10}. No physical ORC data
is needed
+ // because the regression happens before the reader opens the file.
+ Metrics legacyMetrics =
+ new Metrics(2L, null, Map.of(1, 2L, 3, 1L), Map.of(1, 0L, 3, 0L),
null);
+ Metrics healthyMetrics =
+ new Metrics(2L, null, Map.of(1, 2L, 3, 2L), Map.of(1, 0L, 3, 0L),
null);
+ DataFile legacy =
+ DataFiles.builder(spec)
+ .withPath("/path/to/legacy-nested-null.orc")
+ .withFileSizeInBytes(100)
+ .withMetrics(legacyMetrics)
+ .build();
+ DataFile healthy =
+ DataFiles.builder(spec)
+ .withPath("/path/to/healthy-nested.orc")
+ .withFileSizeInBytes(100)
+ .withMetrics(healthyMetrics)
+ .build();
+ DataFile parquet =
+ DataFiles.builder(spec)
+ .withPath("/path/to/healthy-nested.parquet")
+ .withFileSizeInBytes(100)
+ .withMetrics(healthyMetrics)
+ .build();
+
+ OutputFile outputFile =
+ table.ops()
+ .io()
+ .newOutputFile(
+
temp.resolve(manifestFormat().addExtension("legacy-orc-m0")).toString());
+ ManifestWriter<DataFile> writer = ManifestFiles.write(formatVersion, spec,
outputFile, 1000L);
+ try {
+ writer.add(legacy);
+ writer.add(healthy);
+ writer.add(parquet);
+ } finally {
+ writer.close();
+ }
+
+ // Exercise the persisted Avro (V1-V3) or Parquet (V4) manifest, not an
in-memory evaluator.
Review Comment:
Updated.
--
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]