vibhatha commented on code in PR #41861:
URL: https://github.com/apache/arrow/pull/41861#discussion_r1619623819
##########
java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java:
##########
@@ -826,7 +839,120 @@ public void transferTo(BaseVariableWidthViewVector
target) {
*/
public void splitAndTransferTo(int startIndex, int length,
BaseVariableWidthViewVector target) {
- throw new UnsupportedOperationException("splitAndTransferTo function not
supported!");
+ Preconditions.checkArgument(startIndex >= 0 && length >= 0 && startIndex +
length <= valueCount,
+ "Invalid parameters startIndex: %s, length: %s for valueCount: %s",
startIndex, length, valueCount);
+ compareTypes(target, "splitAndTransferTo");
+ target.clear();
+ if (length > 0) {
+ splitAndTransferValidityBuffer(startIndex, length, target);
+ splitAndTransferViewBuffer(startIndex, length, target);
+ splitAndTransferDataBuffers(startIndex, length, target);
+ target.setLastSet(length - 1);
+ target.setValueCount(length);
+ }
+ }
+
+ /* allocate validity buffer */
+ private void allocateValidityBuffer(final long size) {
+ final int curSize = (int) size;
+ validityBuffer = allocator.buffer(curSize);
+ validityBuffer.readerIndex(0);
+ initValidityBuffer();
+ }
+
+ /*
+ * Transfer the validity.
+ */
+ private void splitAndTransferValidityBuffer(int startIndex, int length,
+ BaseVariableWidthViewVector target) {
+ if (length <= 0) {
+ return;
+ }
+
+ final int firstByteSource = BitVectorHelper.byteIndex(startIndex);
+ final int lastByteSource = BitVectorHelper.byteIndex(valueCount - 1);
+ final int byteSizeTarget = getValidityBufferSizeFromCount(length);
+ final int offset = startIndex % 8;
+
+ if (offset == 0) {
+ // slice
+ if (target.validityBuffer != null) {
+ target.validityBuffer.getReferenceManager().release();
+ }
+ final ArrowBuf slicedValidityBuffer =
validityBuffer.slice(firstByteSource, byteSizeTarget);
+ target.validityBuffer = transferBuffer(slicedValidityBuffer,
target.allocator);
+ return;
+ }
+
+ /* Copy data
Review Comment:
I agree. Shall I file an issue and work on it as a follow up?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]