SavicStefan commented on code in PR #59669:
URL: https://github.com/apache/spark/pull/59669#discussion_r4379491359
##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantBuilder.java:
##########
@@ -527,21 +605,42 @@ public void appendVariant(Variant v) {
}
private void appendVariantImpl(byte[] value, byte[] metadata, int pos) {
+ appendVariantImpl(value, metadata, pos, false);
+ }
+
+ private void appendVariantImpl(
+ byte[] value, byte[] metadata, int pos, boolean needCanonicalization) {
checkIndex(pos, value.length);
int basicType = value[pos] & BASIC_TYPE_MASK;
switch (basicType) {
case OBJECT:
handleObject(value, pos, (size, idSize, offsetSize, idStart,
offsetStart, dataStart) -> {
ArrayList<FieldEntry> fields = new ArrayList<>(size);
int start = writePos;
- for (int i = 0; i < size; ++i) {
- int id = readUnsigned(value, idStart + idSize * i, idSize);
- int offset = readUnsigned(value, offsetStart + offsetSize * i,
offsetSize);
+ Integer[] fieldOrder = null;
+ String[] keys = null;
+ if (needCanonicalization && size > 1) {
+ fieldOrder = new Integer[size];
+ keys = new String[size];
+ int[] newIds = new int[size];
+ for (int fieldIndex = 0; fieldIndex < size; ++fieldIndex) {
+ fieldOrder[fieldIndex] = fieldIndex;
+ int keyId = readUnsigned(value, idStart + idSize * fieldIndex,
idSize);
+ keys[fieldIndex] = getMetadataKey(metadata, keyId);
+ newIds[fieldIndex] = addKey(keys[fieldIndex]);
+ }
+ // `buildCanonicalized` adds the keys in sorted order, so new IDs
follow key order.
+ Arrays.sort(fieldOrder, (left, right) ->
Integer.compare(newIds[left], newIds[right]));
Review Comment:
we need that additional sort because this `finishWritingObject` sorts the
fields IDs and offset in the header, but it does not reorder the encoded fields
values
--
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]