laskoviymishka commented on code in PR #17726:
URL: https://github.com/apache/iceberg/pull/17726#discussion_r4004705399
##########
api/src/main/java/org/apache/iceberg/variants/VariantMetadata.java:
##########
@@ -19,10 +19,15 @@
package org.apache.iceberg.variants;
import java.nio.ByteBuffer;
+import java.util.Comparator;
import java.util.NoSuchElementException;
+import org.apache.iceberg.types.Comparators;
/** A variant metadata dictionary. */
public interface VariantMetadata {
+ /** Unsigned UTF-8 byte order for field names, per VariantEncoding.md's
sorted_strings rule. */
+ Comparator<CharSequence> FIELD_NAME_ORDER = Comparators.charSequences();
Review Comment:
The compat call reads as settled now that the PR body's Compatibility
section spells it out — accept the break, rewrite affected data — so I'm not
asking for a fallback.
The one thing I'd add, and it's not a blocker: that reasoning lives in the
PR body and the miss test, but not in the code that relies on it. I'd either
extend this javadoc or drop a line on the `isSorted` branch in
`SerializedMetadata.id()` noting we take `sorted_strings=1` at face value per
spec, so a pre-PR dict flagged sorted but laid out in UTF-16
(supplementary-plane names) will miss and must be rewritten — keeps it in front
of the next reader who lands on the search. wdyt?
##########
parquet/src/test/java/org/apache/iceberg/parquet/TestVariantMetrics.java:
##########
@@ -607,6 +607,34 @@ public void testShreddedObject() throws IOException {
.isEqualTo(Map.of(1, Types.LongType.get(), 2,
Types.VariantType.get()));
}
+ @Test
+ public void testShreddedObjectBoundFieldsOrderedByUtf8() throws IOException {
+ // U+FFFF is 3 UTF-8 bytes (EF BF BF), U+10000 is 4 (F0 90 80 80); UTF-16
orders them oppositely
+ String threeByteName = new String(Character.toChars(0xFFFF));
+ String fourByteName = new String(Character.toChars(0x10000));
+ VariantMetadata objectMetadata = Variants.metadata(threeByteName,
fourByteName);
+
+ ShreddedObject object0 = Variants.object(objectMetadata);
+ object0.put(threeByteName, Variants.of(1));
+ object0.put(fourByteName, Variants.of(2));
+ ShreddedObject object1 = Variants.object(objectMetadata);
+ object1.put(threeByteName, Variants.of(3));
+ object1.put(fourByteName, Variants.of(4));
+
+ Metrics metrics =
+ writeParquet(
+ (id, name) -> ParquetVariantUtil.toParquetSchema(object0),
+ Variant.of(objectMetadata, object0),
+ Variant.of(objectMetadata, object1));
+
+ String threePath = "$['" + threeByteName + "']";
+ String fourPath = "$['" + fourByteName + "']";
+ VariantObject lowerBounds =
Variant.from(metrics.lowerBounds().get(2)).value().asObject();
+ assertThat(lowerBounds.fieldNames()).containsExactly(threePath, fourPath);
Review Comment:
Small non-blocker, and it's the same shape as the test worry I raised in
round 1: this asserts the field-name order but doesn't actually pin the
ParquetMetrics fix. That `[threePath, fourPath]` ordering comes from
`SerializationState`'s tree map, so if `Sets.newTreeSet(FIELD_NAME_ORDER)` in
`ParquetMetrics.variant()` were reverted to a natural-order set, the dict would
come out `isSorted=false` but `fieldNames()` would still return this same order
and the test passes.
I'd add an assert that the backing metadata is `isSorted()` (cast the
lower-bound metadata to `SerializedMetadata`) so it guards the line it's here
for. wdyt?
##########
core/src/test/java/org/apache/iceberg/variants/TestVariantMetadataFieldOrdering.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.variants;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Test;
+
+public class TestVariantMetadataFieldOrdering {
+
+ // U+FFFF encodes to 3 UTF-8 bytes (EF BF BF), U+10000 to 4 (F0 90 80 80)
+ private static final String NAME_3_BYTE = new
String(Character.toChars(0xFFFF));
+ private static final String NAME_4_BYTE = new
String(Character.toChars(0x10000));
+
+ @Test
+ public void utf8OrderedDictionaryIsSortedAndOrdered() {
Review Comment:
Small non-blocker: these three drop the `test` prefix the rest of the
package uses (the new `testShreddedFieldOrderFollowsUtf8ByteOrder` right in
this PR, all of `TestShreddedObject`). Some tooling pattern-matches on it, so
I'd rename to `testUtf8OrderedDictionaryIsSortedAndOrdered` and friends to stay
consistent.
--
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]