This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 8a76082e3a GH-40930: [Java] Implement a function to retrieve reference 
buffers in StringView (#41796)
8a76082e3a is described below

commit 8a76082e3a4b31ba74063093a3f279726625e245
Author: Vibhatha Lakmal Abeykoon <[email protected]>
AuthorDate: Fri May 24 09:28:19 2024 +0530

    GH-40930: [Java] Implement a function to retrieve reference buffers in 
StringView (#41796)
    
    ### Rationale for this change
    
    This PR includes a minor changes to the `getBuffers` method in 
`BaseVariableWidthViewVector`.
    
    ### What changes are included in this PR?
    
    Previously the fixed buffers were the only ones returned from this method 
because of lack of clarity in the initial implementation stage. In this PR, it 
includes the variadic buffers to the result. A test case has also being added.
    
    ### Are these changes tested?
    
    Yes
    
    ### Are there any user-facing changes?
    
    No
    * GitHub Issue: #40930
    
    Authored-by: Vibhatha Lakmal Abeykoon <[email protected]>
    Signed-off-by: David Li <[email protected]>
---
 .../apache/arrow/vector/BaseVariableWidthViewVector.java  | 15 +++++++--------
 .../java/org/apache/arrow/vector/TestVectorReset.java     | 12 ++++++++++++
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git 
a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java
 
b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java
index ec700a0dc2..620b998994 100644
--- 
a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java
+++ 
b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java
@@ -703,13 +703,6 @@ public abstract class BaseVariableWidthViewVector extends 
BaseValueVector implem
    * impact the reference counts for this buffer, so it only should be used 
for in-context
    * access. Also note that this buffer changes regularly, thus
    * external classes shouldn't hold a reference to it (unless they change it).
-   * <p>
-   * Note: This method only returns validityBuffer and valueBuffer.
-   * But it doesn't return the data buffers.
-   * <p>
-   * TODO: Implement a strategy to retrieve the data buffers.
-   * <a href="https://github.com/apache/arrow/issues/40930";>data buffer 
retrieval.</a>
-   *
    * @param clear Whether to clear vector before returning, the buffers will 
still be refcounted
    *              but the returned array will be the only reference to them
    * @return The underlying {@link ArrowBuf buffers} that is used by this
@@ -722,9 +715,15 @@ public abstract class BaseVariableWidthViewVector extends 
BaseValueVector implem
     if (getBufferSize() == 0) {
       buffers = new ArrowBuf[0];
     } else {
-      buffers = new ArrowBuf[2];
+      final int dataBufferSize = dataBuffers.size();
+      // validity and view buffers
+      final int fixedBufferSize = 2;
+      buffers = new ArrowBuf[fixedBufferSize + dataBufferSize];
       buffers[0] = validityBuffer;
       buffers[1] = viewBuffer;
+      for (int i = fixedBufferSize; i < fixedBufferSize + dataBufferSize; i++) 
{
+        buffers[i] = dataBuffers.get(i - fixedBufferSize);
+      }
     }
     if (clear) {
       for (final ArrowBuf buffer : buffers) {
diff --git 
a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java 
b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java
index 71009a3337..19700e0216 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java
@@ -93,6 +93,18 @@ public class TestVectorReset {
     }
   }
 
+  @Test
+  public void testVariableViewTypeReset() {
+    try (final ViewVarCharVector vector = new ViewVarCharVector("ViewVarChar", 
allocator)) {
+      vector.allocateNewSafe();
+      vector.set(0, "a".getBytes(StandardCharsets.UTF_8));
+      vector.setLastSet(0);
+      vector.setValueCount(1);
+      resetVectorAndVerify(vector, vector.getBuffers(false));
+      assertEquals(-1, vector.getLastSet());
+    }
+  }
+
   @Test
   public void testLargeVariableTypeReset() {
     try (final LargeVarCharVector vector = new 
LargeVarCharVector("LargeVarChar", allocator)) {

Reply via email to