2323import org .apache .arrow .memory .ArrowBuf ;
2424import org .apache .arrow .memory .BufferAllocator ;
2525import org .apache .arrow .memory .util .ArrowBufPointer ;
26+ import org .apache .arrow .memory .util .ByteFunctionHelpers ;
2627import org .apache .arrow .memory .util .hash .ArrowBufHasher ;
28+ import org .apache .arrow .util .Preconditions ;
2729import org .apache .arrow .vector .complex .impl .UuidReaderImpl ;
2830import org .apache .arrow .vector .complex .reader .FieldReader ;
2931import org .apache .arrow .vector .extension .UuidType ;
32+ import org .apache .arrow .vector .holders .ExtensionHolder ;
3033import org .apache .arrow .vector .holders .NullableUuidHolder ;
3134import org .apache .arrow .vector .holders .UuidHolder ;
3235import org .apache .arrow .vector .types .pojo .Field ;
@@ -132,7 +135,8 @@ public int hashCode(int index) {
132135
133136 @ Override
134137 public int hashCode (int index , ArrowBufHasher hasher ) {
135- return getUnderlyingVector ().hashCode (index , hasher );
138+ int start = this .getStartOffset (index );
139+ return ByteFunctionHelpers .hash (hasher , this .getDataBuffer (), start , start + UUID_BYTE_WIDTH );
136140 }
137141
138142 /**
@@ -146,17 +150,19 @@ public int isSet(int index) {
146150 }
147151
148152 /**
149- * Gets the UUID value at the given index as an ArrowBuf .
153+ * Reads the UUID value at the given index into a UuidHolder .
150154 *
151- * @param index the index to retrieve
152- * @return a buffer slice containing the 16-byte UUID
153- * @throws IllegalStateException if the value at the index is null and null checking is enabled
155+ * @param index the index to read from
156+ * @param holder the holder to populate with the UUID data
154157 */
155- public ArrowBuf get (int index ) throws IllegalStateException {
158+ public void get (int index , UuidHolder holder ) {
159+ Preconditions .checkArgument (index >= 0 , "Cannot get negative index in UUID vector." );
156160 if (NullCheckingForGet .NULL_CHECKING_ENABLED && this .isSet (index ) == 0 ) {
157- throw new IllegalStateException ( "Value at index is null" ) ;
161+ holder . isSet = 0 ;
158162 } else {
159- return getBufferSlicePostNullCheck (index );
163+ holder .isSet = 1 ;
164+ holder .buffer = getDataBuffer ();
165+ holder .start = getStartOffset (index );
160166 }
161167 }
162168
@@ -167,23 +173,24 @@ public ArrowBuf get(int index) throws IllegalStateException {
167173 * @param holder the holder to populate with the UUID data
168174 */
169175 public void get (int index , NullableUuidHolder holder ) {
176+ Preconditions .checkArgument (index >= 0 , "Cannot get negative index in UUID vector." );
170177 if (NullCheckingForGet .NULL_CHECKING_ENABLED && this .isSet (index ) == 0 ) {
171178 holder .isSet = 0 ;
172179 } else {
173180 holder .isSet = 1 ;
174- holder .buffer = getBufferSlicePostNullCheck (index );
181+ holder .buffer = getDataBuffer ();
182+ holder .start = getStartOffset (index );
175183 }
176184 }
177185
178186 /**
179- * Reads the UUID value at the given index into a UuidHolder .
187+ * Calculates the byte offset for a given index in the data buffer .
180188 *
181- * @param index the index to read from
182- * @param holder the holder to populate with the UUID data
189+ * @param index the index of the UUID value
190+ * @return the byte offset in the data buffer
183191 */
184- public void get (int index , UuidHolder holder ) {
185- holder .isSet = 1 ;
186- holder .buffer = getBufferSlicePostNullCheck (index );
192+ public final int getStartOffset (int index ) {
193+ return index * UUID_BYTE_WIDTH ;
187194 }
188195
189196 /**
@@ -207,7 +214,7 @@ public void set(int index, UUID value) {
207214 * @param holder the holder containing the UUID data
208215 */
209216 public void set (int index , UuidHolder holder ) {
210- this .set (index , holder .isSet , holder .buffer );
217+ this .set (index , holder .buffer , holder .start );
211218 }
212219
213220 /**
@@ -217,28 +224,11 @@ public void set(int index, UuidHolder holder) {
217224 * @param holder the holder containing the UUID data
218225 */
219226 public void set (int index , NullableUuidHolder holder ) {
220- this .set (index , holder .isSet , holder .buffer );
221- }
222-
223- /**
224- * Sets the UUID value at the given index with explicit null flag.
225- *
226- * @param index the index to set
227- * @param isSet 1 if the value is set, 0 if null
228- * @param buffer the buffer containing the 16-byte UUID data
229- */
230- public void set (int index , int isSet , ArrowBuf buffer ) {
231- getUnderlyingVector ().set (index , isSet , buffer );
232- }
233-
234- /**
235- * Sets the UUID value at the given index from an ArrowBuf.
236- *
237- * @param index the index to set
238- * @param value the buffer containing the 16-byte UUID data
239- */
240- public void set (int index , ArrowBuf value ) {
241- getUnderlyingVector ().set (index , value );
227+ if (holder .isSet == 0 ) {
228+ getUnderlyingVector ().setNull (index );
229+ } else {
230+ this .set (index , holder .buffer , holder .start );
231+ }
242232 }
243233
244234 /**
@@ -249,10 +239,12 @@ public void set(int index, ArrowBuf value) {
249239 * @param sourceOffset the offset in the source buffer where the UUID data starts
250240 */
251241 public void set (int index , ArrowBuf source , int sourceOffset ) {
252- // Copy bytes from source buffer to target vector data buffer
253- ArrowBuf dataBuffer = getUnderlyingVector ().getDataBuffer ();
254- dataBuffer .setBytes ((long ) index * UUID_BYTE_WIDTH , source , sourceOffset , UUID_BYTE_WIDTH );
255- getUnderlyingVector ().setIndexDefined (index );
242+ Preconditions .checkNotNull (source , "Cannot set UUID vector, the source buffer is null." );
243+
244+ BitVectorHelper .setBit (getUnderlyingVector ().getValidityBuffer (), index );
245+ getUnderlyingVector ()
246+ .getDataBuffer ()
247+ .setBytes ((long ) index * UUID_BYTE_WIDTH , source , sourceOffset , UUID_BYTE_WIDTH );
256248 }
257249
258250 /**
@@ -286,25 +278,34 @@ public void setSafe(int index, UUID value) {
286278 * @param holder the holder containing the UUID data, or null to set a null value
287279 */
288280 public void setSafe (int index , NullableUuidHolder holder ) {
289- if (holder != null ) {
290- getUnderlyingVector ().setSafe (index , holder .isSet , holder .buffer );
291- } else {
281+ if (holder == null || holder .isSet == 0 ) {
292282 getUnderlyingVector ().setNull (index );
283+ } else {
284+ this .setSafe (index , holder .buffer , holder .start );
293285 }
294286 }
295287
296288 /**
297289 * Sets the UUID value at the given index from a UuidHolder, expanding capacity if needed.
298290 *
299291 * @param index the index to set
300- * @param holder the holder containing the UUID data, or null to set a null value
292+ * @param holder the holder containing the UUID data
301293 */
302294 public void setSafe (int index , UuidHolder holder ) {
303- if (holder != null ) {
304- getUnderlyingVector ().setSafe (index , holder .isSet , holder .buffer );
305- } else {
306- getUnderlyingVector ().setNull (index );
307- }
295+ this .setSafe (index , holder .buffer , holder .start );
296+ }
297+
298+ /**
299+ * Sets the UUID value at the given index by copying from a source buffer, expanding capacity if
300+ * needed.
301+ *
302+ * @param index the index to set
303+ * @param buffer the source buffer to copy from
304+ * @param start the offset in the source buffer where the UUID data starts
305+ */
306+ public void setSafe (int index , ArrowBuf buffer , int start ) {
307+ getUnderlyingVector ().handleSafe (index );
308+ this .set (index , buffer , start );
308309 }
309310
310311 /**
@@ -400,15 +401,9 @@ public TransferPair getTransferPair(BufferAllocator allocator) {
400401 return getTransferPair (this .getField ().getName (), allocator );
401402 }
402403
403- private ArrowBuf getBufferSlicePostNullCheck (int index ) {
404- return getUnderlyingVector ()
405- .getDataBuffer ()
406- .slice ((long ) index * UUID_BYTE_WIDTH , UUID_BYTE_WIDTH );
407- }
408-
409404 @ Override
410405 public int getTypeWidth () {
411- return getUnderlyingVector (). getTypeWidth () ;
406+ return UUID_BYTE_WIDTH ;
412407 }
413408
414409 /** {@link TransferPair} for {@link UuidVector}. */
0 commit comments