SavicStefan commented on code in PR #59669:
URL: https://github.com/apache/spark/pull/59669#discussion_r4574675641
##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantBuilder.java:
##########
@@ -527,21 +843,44 @@ public void appendVariant(Variant v) {
}
private void appendVariantImpl(byte[] value, byte[] metadata, int pos) {
+ appendVariantImpl(value, metadata, pos, null);
+ }
+
+ private void appendVariantImpl(
+ byte[] value, byte[] metadata, int pos, int[] canonicalIds) {
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;
+ if (canonicalIds != null && size > 1) {
+ fieldOrder = new Integer[size];
+ int[] newIds = new int[size];
+ for (int fieldIndex = 0; fieldIndex < size; ++fieldIndex) {
+ fieldOrder[fieldIndex] = fieldIndex;
+ int keyId = readUnsigned(value, idStart + idSize * fieldIndex,
idSize);
+ newIds[fieldIndex] = canonicalIds[keyId];
+ }
+ // Write values in key order; finishWritingObject only sorts the
header entries.
+ // `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:
added the check to first see do we need to sort and if so, we will sort 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]