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 ;
@@ -132,7 +134,8 @@ public int hashCode(int index) {
132134
133135 @ Override
134136 public int hashCode (int index , ArrowBufHasher hasher ) {
135- return getUnderlyingVector ().hashCode (index , hasher );
137+ int start = this .getStartOffset (index );
138+ return ByteFunctionHelpers .hash (hasher , this .getDataBuffer (), start , start + UUID_BYTE_WIDTH );
136139 }
137140
138141 /**
@@ -145,45 +148,31 @@ public int isSet(int index) {
145148 return getUnderlyingVector ().isSet (index );
146149 }
147150
148- /**
149- * Gets the UUID value at the given index as an ArrowBuf.
150- *
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
154- */
155- public ArrowBuf get (int index ) throws IllegalStateException {
156- if (NullCheckingForGet .NULL_CHECKING_ENABLED && this .isSet (index ) == 0 ) {
157- throw new IllegalStateException ("Value at index is null" );
158- } else {
159- return getBufferSlicePostNullCheck (index );
160- }
161- }
162-
163151 /**
164152 * Reads the UUID value at the given index into a NullableUuidHolder.
165153 *
166154 * @param index the index to read from
167155 * @param holder the holder to populate with the UUID data
168156 */
169157 public void get (int index , NullableUuidHolder holder ) {
170- if (NullCheckingForGet .NULL_CHECKING_ENABLED && this .isSet (index ) == 0 ) {
158+ Preconditions .checkArgument (index >= 0 , "Cannot get negative index in UUID vector." );
159+ if (isSet (index ) == 0 ) {
171160 holder .isSet = 0 ;
172- } else {
173- holder .isSet = 1 ;
174- holder .buffer = getBufferSlicePostNullCheck (index );
161+ return ;
175162 }
163+ holder .isSet = 1 ;
164+ holder .buffer = getDataBuffer ();
165+ holder .start = getStartOffset (index );
176166 }
177167
178168 /**
179- * Reads the UUID value at the given index into a UuidHolder .
169+ * Calculates the byte offset for a given index in the data buffer .
180170 *
181- * @param index the index to read from
182- * @param holder the holder to populate with the UUID data
171+ * @param index the index of the UUID value
172+ * @return the byte offset in the data buffer
183173 */
184- public void get (int index , UuidHolder holder ) {
185- holder .isSet = 1 ;
186- holder .buffer = getBufferSlicePostNullCheck (index );
174+ public final int getStartOffset (int index ) {
175+ return index * UUID_BYTE_WIDTH ;
187176 }
188177
189178 /**
@@ -207,7 +196,7 @@ public void set(int index, UUID value) {
207196 * @param holder the holder containing the UUID data
208197 */
209198 public void set (int index , UuidHolder holder ) {
210- this .set (index , holder .isSet , holder .buffer );
199+ this .set (index , holder .buffer , holder .start );
211200 }
212201
213202 /**
@@ -217,28 +206,11 @@ public void set(int index, UuidHolder holder) {
217206 * @param holder the holder containing the UUID data
218207 */
219208 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 );
209+ if (holder .isSet == 0 ) {
210+ getUnderlyingVector ().setNull (index );
211+ } else {
212+ this .set (index , holder .buffer , holder .start );
213+ }
242214 }
243215
244216 /**
@@ -249,10 +221,12 @@ public void set(int index, ArrowBuf value) {
249221 * @param sourceOffset the offset in the source buffer where the UUID data starts
250222 */
251223 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 );
224+ Preconditions .checkNotNull (source , "Cannot set UUID vector, the source buffer is null." );
225+
226+ BitVectorHelper .setBit (getUnderlyingVector ().getValidityBuffer (), index );
227+ getUnderlyingVector ()
228+ .getDataBuffer ()
229+ .setBytes ((long ) index * UUID_BYTE_WIDTH , source , sourceOffset , UUID_BYTE_WIDTH );
256230 }
257231
258232 /**
@@ -286,25 +260,34 @@ public void setSafe(int index, UUID value) {
286260 * @param holder the holder containing the UUID data, or null to set a null value
287261 */
288262 public void setSafe (int index , NullableUuidHolder holder ) {
289- if (holder != null ) {
290- getUnderlyingVector ().setSafe (index , holder .isSet , holder .buffer );
291- } else {
263+ if (holder == null || holder .isSet == 0 ) {
292264 getUnderlyingVector ().setNull (index );
265+ } else {
266+ this .setSafe (index , holder .buffer , holder .start );
293267 }
294268 }
295269
296270 /**
297271 * Sets the UUID value at the given index from a UuidHolder, expanding capacity if needed.
298272 *
299273 * @param index the index to set
300- * @param holder the holder containing the UUID data, or null to set a null value
274+ * @param holder the holder containing the UUID data
301275 */
302276 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- }
277+ this .setSafe (index , holder .buffer , holder .start );
278+ }
279+
280+ /**
281+ * Sets the UUID value at the given index by copying from a source buffer, expanding capacity if
282+ * needed.
283+ *
284+ * @param index the index to set
285+ * @param buffer the source buffer to copy from
286+ * @param start the offset in the source buffer where the UUID data starts
287+ */
288+ public void setSafe (int index , ArrowBuf buffer , int start ) {
289+ getUnderlyingVector ().handleSafe (index );
290+ this .set (index , buffer , start );
308291 }
309292
310293 /**
@@ -400,15 +383,9 @@ public TransferPair getTransferPair(BufferAllocator allocator) {
400383 return getTransferPair (this .getField ().getName (), allocator );
401384 }
402385
403- private ArrowBuf getBufferSlicePostNullCheck (int index ) {
404- return getUnderlyingVector ()
405- .getDataBuffer ()
406- .slice ((long ) index * UUID_BYTE_WIDTH , UUID_BYTE_WIDTH );
407- }
408-
409386 @ Override
410387 public int getTypeWidth () {
411- return getUnderlyingVector (). getTypeWidth () ;
388+ return UUID_BYTE_WIDTH ;
412389 }
413390
414391 /** {@link TransferPair} for {@link UuidVector}. */
0 commit comments