huaxingao commented on code in PR #15996:
URL: https://github.com/apache/iceberg/pull/15996#discussion_r3406690559


##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/StructLikeSerializer.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.flink.maintenance.operator;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+import org.apache.iceberg.PartitionData;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.types.Conversions;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+
+/**
+ * Serializer for {@link StructLike} tuples. Two entry points:
+ *
+ * <ul>
+ *   <li>{@link #serializeKey} builds a Flink keyed-state key ({@link 
SerializedEqualityValues}),
+ *       prefixed with the partition spec id so partition evolution keeps 
specs disjoint.
+ *   <li>{@link #encodePartition} / {@link #decodePartition} serialize 
partition tuples into bytes.
+ * </ul>
+ */
+class StructLikeSerializer {
+
+  static final byte[] EMPTY_PARTITION = new byte[0];
+
+  private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+  private final DataOutputStream dos = new DataOutputStream(baos);
+
+  public SerializedEqualityValues serializeKey(
+      StructLike key, Types.StructType keyType, int specId) {
+    baos.reset();
+    try {
+      dos.writeInt(specId);

Review Comment:
   Keying on `specId` makes eq-delete resolution spec-sensitive, but equality 
deletes are value-scoped and should match across specs. After partition 
evolution, a row indexed under the old spec `(key (A, id))` won't be matched by 
an eq-delete written under the new spec `(key (B, id))`, so the delete silently 
misses and the row stays visible. Equality field IDs are stable across 
evolution and partition columns are a subset of the equality fields, so the 
values alone identify the row. Could we drop specId from the key, or else fail 
fast when a staging file uses a non-current spec so the limitation is explicit?



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