mxm commented on code in PR #18610:
URL: https://github.com/apache/iceberg/pull/18610#discussion_r4360062815


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/EqualityConvertReader.java:
##########
@@ -159,13 +160,17 @@ private void processDataFile(
         builder.project(readSchema).reuseContainers().build()) {
       Accessor<StructLike> posAccessor =
           readSchema.accessorForField(MetadataColumns.ROW_POSITION.fieldId());
+      // Generic records hold java.time values; the serializer expects 
Iceberg's internal
+      // representation (e.g. days for DATE, micros for TIMESTAMP).
+      InternalRecordWrapper keyWrapper = new 
InternalRecordWrapper(readSchema.asStruct());
       for (Record record : records) {
         long position = (long) posAccessor.get(record);
         if (existingDeletes != null && existingDeletes.isDeleted(position)) {
           continue;
         }
 
-        SerializedEqualityValues key = fieldSerializer.serializeKey(record, 
keySchema.asStruct());
+        SerializedEqualityValues key =
+            fieldSerializer.serializeKey(keyWrapper.wrap(record), 
keySchema.asStruct());

Review Comment:
   We can do this in a follow-up. The added test already verifies the 
conversion works correctly. Merely changing the JavaDoc would be fine for this 
PR.



##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/EqualityConvertReader.java:
##########
@@ -159,13 +160,17 @@ private void processDataFile(
         builder.project(readSchema).reuseContainers().build()) {
       Accessor<StructLike> posAccessor =
           readSchema.accessorForField(MetadataColumns.ROW_POSITION.fieldId());
+      // Generic records hold java.time values; the serializer expects 
Iceberg's internal
+      // representation (e.g. days for DATE, micros for TIMESTAMP).
+      InternalRecordWrapper keyWrapper = new 
InternalRecordWrapper(readSchema.asStruct());

Review Comment:
   +1 for creating it once in open. 



##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/EqualityConvertReader.java:
##########
@@ -159,13 +160,17 @@ private void processDataFile(
         builder.project(readSchema).reuseContainers().build()) {
       Accessor<StructLike> posAccessor =
           readSchema.accessorForField(MetadataColumns.ROW_POSITION.fieldId());
+      // Generic records hold java.time values; the serializer expects 
Iceberg's internal
+      // representation (e.g. days for DATE, micros for TIMESTAMP).
+      InternalRecordWrapper keyWrapper = new 
InternalRecordWrapper(readSchema.asStruct());
       for (Record record : records) {
         long position = (long) posAccessor.get(record);
         if (existingDeletes != null && existingDeletes.isDeleted(position)) {
           continue;
         }
 
-        SerializedEqualityValues key = fieldSerializer.serializeKey(record, 
keySchema.asStruct());
+        SerializedEqualityValues key =
+            fieldSerializer.serializeKey(keyWrapper.wrap(record), 
keySchema.asStruct());

Review Comment:
   This is really an oddity of `GenericRecord` which is a `StructLike` but 
returns non-internal Iceberg types. Generally speaking, there is no way of 
knowing whether a StructLike is internal and external.
   
   I think the best way is to be explicit in the serializer and change the 
signature:
   
   ```java
     public SerializedEqualityValues serializeKey(Record key) {
   ```
   
   Note the dropped key type: To avoid the per Record creation of 
InternalRecordWrapper, we would create InternalRecordWrapper and store it as a 
field when we constructor StructLikeSerializer.
   
   We can then test the serializer for all types explicitly.
   
   I guess we would have to rename StructLikeSerializer to `RecordSerializer` 
then :)



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