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


##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantBuilder.java:
##########
@@ -205,6 +205,231 @@ public static Variant pickAtPaths(Variant v, PickNode 
tree) {
     return builder.result();
   }
 
+  /**
+   * Return {@code v} in canonical form, or {@code v} itself if it is already 
canonical.
+   * <p>
+   * The variant binary encoding allows the same logical value to be encoded 
in several ways
+   * (dictionary order, unused keys, integer and offset widths, decimal scale, 
...). Canonical form
+   * picks one encoding per value, so that values which are equal under the 
variant equality rules
+   * have identical {@code value} and {@code metadata} bytes and can be 
compared, hashed and
+   * grouped bytewise. It is a Spark-internal normalization, not part of the 
variant spec, and
+   * nothing outside Spark is expected to produce or require it.
+   * <p>
+   * A variant is canonical when all of the following hold.
+   * <ul>
+   *   <li>Metadata header: version {@link VariantUtil#VERSION}, the minimal 
offset size for
+   *       {@code max(lastOffset, numKeys)}, i.e. 1, 2, 3 or 4 bytes as given 
by
+   *       {@code getIntegerSize}, and {@code sorted_strings} and the unused 
bit 5 clear.
+   *       {@code sorted_strings} stays clear although canonical keys are 
sorted, so that builder
+   *       output, which never sets it, is already canonical.</li>
+   *   <li>Metadata dictionary: the first offset is 0, offsets are 
non-decreasing, the key bytes
+   *       end exactly at the last offset (no trailing bytes), keys are 
strictly increasing under
+   *       unsigned byte comparison (so they are unique), and every key is 
referenced by at least
+   *       one object field. Key bytes are preserved as is, including invalid 
UTF-8.</li>
+   *   <li>Value root: starts at position 0 and spans exactly {@code 
value.length} bytes.</li>
+   *   <li>Object: field ids strictly increasing (fields are stored in key 
order and no key is
+   *       repeated), field data stored contiguously in field order, the end 
offset equal to the
+   *       data size, and the header using the minimal id size for the largest 
id, the minimal
+   *       offset size for the data size, {@code is_large} only for more than 
255 fields, and the
+   *       reserved bit 7 clear.</li>
+   *   <li>Array: element order preserved, element data stored contiguously in 
element order, the

Review Comment:
   removed it



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