Skip to content

Commit

Permalink
GH-40930: [Java] Implement a function to retrieve reference buffers i…
Browse files Browse the repository at this point in the history
…n 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 <vibhatha@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
vibhatha committed May 24, 2024
1 parent 417a86b commit 8a76082
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,6 @@ public Field getField() {
* 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
Expand All @@ -722,9 +715,15 @@ public ArrowBuf[] getBuffers(boolean clear) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ public void testVariableTypeReset() {
}
}

@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)) {
Expand Down

0 comments on commit 8a76082

Please sign in to comment.