SavicStefan commented on code in PR #59669:
URL: https://github.com/apache/spark/pull/59669#discussion_r4552013832


##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantBuilder.java:
##########
@@ -465,8 +694,13 @@ public void finishWritingObject(int start, 
ArrayList<FieldEntry> fields) {
     } else {
       for (int i = 1; i < size; ++i) {
         maxId = Math.max(maxId, fields.get(i).id);
-        String key = fields.get(i).key;
-        if (key.equals(fields.get(i - 1).key)) {
+        FieldEntry field = fields.get(i);
+        FieldEntry previous = fields.get(i - 1);
+        boolean duplicate = field.key == null ? field.id == previous.id :
+            field.key.equals(previous.key);
+        if (duplicate) {
+          String key = field.key != null ? field.key :
+              new String(field.keyBytes, StandardCharsets.UTF_8);

Review Comment:
   the canonical rebuild creates `FieldEntry` from the raw key bytes `(key == 
null)` so keys are not decoded per field, the duplicate check therefore 
compares `id`, as the `allowDuplicateKeys` branch above already does and 
decodes the bytes only for the error message, because like without this, 
`key.equals` would NPE on every canonicalized object with more than one field



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