Skip to content

Commit 51cf225

Browse files
committed
use ArrowBuf.getLong
1 parent c9b09b0 commit 51cf225

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

vector/src/main/java/org/apache/arrow/vector/UuidVector.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.arrow.vector;
1818

19+
import static org.apache.arrow.memory.util.MemoryUtil.LITTLE_ENDIAN;
1920
import static org.apache.arrow.vector.extension.UuidType.UUID_BYTE_WIDTH;
2021

2122
import java.nio.ByteBuffer;
@@ -156,13 +157,17 @@ public int isSet(int index) {
156157
*/
157158
public void get(int index, UuidHolder holder) {
158159
Preconditions.checkArgument(index >= 0, "Cannot get negative index in UUID vector.");
159-
if (NullCheckingForGet.NULL_CHECKING_ENABLED && this.isSet(index) == 0) {
160-
holder.isSet = 0;
160+
final ArrowBuf dataBuffer = getUnderlyingVector().getDataBuffer();
161+
final long start = (long) index * UUID_BYTE_WIDTH;
162+
final long next = start + Long.BYTES;
163+
// UUIDs are stored in big-endian byte order in Arrow buffers.
164+
// ArrowBuf.getLong() reads in native byte order, so we need to reverse bytes on LE systems.
165+
if (LITTLE_ENDIAN) {
166+
holder.mostSigBits = Long.reverseBytes(dataBuffer.getLong(start));
167+
holder.leastSigBits = Long.reverseBytes(dataBuffer.getLong(next));
161168
} else {
162-
holder.isSet = 1;
163-
final ByteBuffer bb = ByteBuffer.wrap(getUnderlyingVector().getObject(index));
164-
holder.mostSigBits = bb.getLong();
165-
holder.leastSigBits = bb.getLong();
169+
holder.mostSigBits = dataBuffer.getLong(start);
170+
holder.leastSigBits = dataBuffer.getLong(next);
166171
}
167172
}
168173

@@ -178,9 +183,17 @@ public void get(int index, NullableUuidHolder holder) {
178183
holder.isSet = 0;
179184
} else {
180185
holder.isSet = 1;
181-
final ByteBuffer bb = ByteBuffer.wrap(getUnderlyingVector().getObject(index));
182-
holder.mostSigBits = bb.getLong();
183-
holder.leastSigBits = bb.getLong();
186+
final ArrowBuf dataBuffer = getUnderlyingVector().getDataBuffer();
187+
final long offset = (long) index * UUID_BYTE_WIDTH;
188+
// UUIDs are stored in big-endian byte order in Arrow buffers.
189+
// ArrowBuf.getLong() reads in native byte order, so we need to reverse bytes on LE systems.
190+
if (LITTLE_ENDIAN) {
191+
holder.mostSigBits = Long.reverseBytes(dataBuffer.getLong(offset));
192+
holder.leastSigBits = Long.reverseBytes(dataBuffer.getLong(offset + Long.BYTES));
193+
} else {
194+
holder.mostSigBits = dataBuffer.getLong(offset);
195+
holder.leastSigBits = dataBuffer.getLong(offset + Long.BYTES);
196+
}
184197
}
185198
}
186199

@@ -244,8 +257,8 @@ public void set(int index, ArrowBuf source, int sourceOffset) {
244257

245258
BitVectorHelper.setBit(getUnderlyingVector().getValidityBuffer(), index);
246259
getUnderlyingVector()
247-
.getDataBuffer()
248-
.setBytes((long) index * UUID_BYTE_WIDTH, source, sourceOffset, UUID_BYTE_WIDTH);
260+
.getDataBuffer()
261+
.setBytes((long) index * UUID_BYTE_WIDTH, source, sourceOffset, UUID_BYTE_WIDTH);
249262
}
250263

251264
/**

vector/src/main/java/org/apache/arrow/vector/complex/impl/NullableUuidHolderReaderImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.arrow.vector.complex.impl;
1818

19-
import java.util.UUID;
2019
import org.apache.arrow.vector.holders.ExtensionHolder;
2120
import org.apache.arrow.vector.holders.NullableUuidHolder;
2221
import org.apache.arrow.vector.holders.UuidHolder;
@@ -107,4 +106,3 @@ public Object readObject() {
107106
return holder.getUuid();
108107
}
109108
}
110-

vector/src/main/java/org/apache/arrow/vector/holders/NullableUuidHolder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ public class NullableUuidHolder extends ExtensionHolder {
3636
/** The least significant 64 bits of the UUID. */
3737
public long leastSigBits;
3838

39+
/**
40+
* Converts the holder's two longs to a UUID object.
41+
*
42+
* @return the UUID represented by this holder, or null if isSet is 0
43+
*/
3944
public UUID getUuid() {
40-
if(this.isSet == 0) {
45+
if (this.isSet == 0) {
4146
return null;
4247
}
4348
return new UUID(mostSigBits, leastSigBits);

vector/src/main/java/org/apache/arrow/vector/holders/UuidHolder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public UuidHolder() {
3939
this.isSet = 1;
4040
}
4141

42+
/**
43+
* Converts the holder's two longs to a UUID object.
44+
*
45+
* @return the UUID represented by this holder
46+
*/
4247
public UUID getUuid() {
4348
return new UUID(mostSigBits, leastSigBits);
4449
}

0 commit comments

Comments
 (0)