Skip to content

Commit c220c3c

Browse files
committed
Return java.util.UUID
1 parent db6b98e commit c220c3c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

parquet-variant/src/main/java/org/apache/parquet/variant/Variant.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ public byte[] getBinary() {
131131
* @return the UUID value
132132
*/
133133
public UUID getUUID() {
134-
byte[] uuidBytes = VariantUtil.getUUID(value, pos);
135-
long msb = ByteBuffer.wrap(uuidBytes, 0, 8).order(ByteOrder.BIG_ENDIAN).getLong();
136-
long lsb = ByteBuffer.wrap(uuidBytes, 8, 8).order(ByteOrder.BIG_ENDIAN).getLong();
137-
return new UUID(msb, lsb);
134+
return VariantUtil.getUUID(value, pos);
138135
}
139136

140137
/**
@@ -540,8 +537,7 @@ private static void toJsonImpl(
540537
}
541538
break;
542539
case UUID:
543-
ByteBuffer bb = ByteBuffer.wrap(VariantUtil.getUUID(value, pos)).order(ByteOrder.BIG_ENDIAN);
544-
gen.writeString(new java.util.UUID(bb.getLong(), bb.getLong()).toString());
540+
gen.writeString(VariantUtil.getUUID(value, pos).toString());
545541
break;
546542
default:
547543
throw new IllegalArgumentException("Unsupported type: " + VariantUtil.getType(value, pos));

parquet-variant/src/main/java/org/apache/parquet/variant/VariantUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.math.BigDecimal;
2020
import java.math.BigInteger;
21+
import java.nio.ByteBuffer;
22+
import java.nio.ByteOrder;
2123
import java.util.Arrays;
2224

2325
/**
@@ -594,14 +596,15 @@ public static String getString(byte[] value, int pos) {
594596
throw unexpectedType(Type.STRING);
595597
}
596598

597-
public static byte[] getUUID(byte[] value, int pos) {
599+
public static java.util.UUID getUUID(byte[] value, int pos) {
598600
checkIndex(pos, value.length);
599601
int basicType = value[pos] & BASIC_TYPE_MASK;
600602
int typeInfo = (value[pos] >> BASIC_TYPE_BITS) & PRIMITIVE_TYPE_MASK;
601603
if (basicType != PRIMITIVE || typeInfo != UUID) throw unexpectedType(Type.UUID);
602604
int start = pos + 1;
603605
checkIndex(start + UUID_SIZE - 1, value.length);
604-
return Arrays.copyOfRange(value, start, start + UUID_SIZE);
606+
ByteBuffer bb = ByteBuffer.wrap(value, start, UUID_SIZE).order(ByteOrder.BIG_ENDIAN);
607+
return new java.util.UUID(bb.getLong(), bb.getLong());
605608
}
606609

607610
/**

0 commit comments

Comments
 (0)