Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-40930: [Java] Implement a function to retrieve reference buffers in StringView #41796

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading