Skip to content
Closed
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
6 changes: 2 additions & 4 deletions java/vector/src/main/codegen/templates/UnionVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,8 @@ public void transfer() {

@Override
public void splitAndTransfer(int startIndex, int length) {
to.allocateNew();
for (int i = 0; i < length; i++) {
to.copyFromSafe(startIndex + i, i, org.apache.arrow.vector.complex.UnionVector.this);
}
internalMapVectorTransferPair.splitAndTransfer(startIndex, length);
typeVectorTransferPair.splitAndTransfer(startIndex, length);
to.getMutator().setValueCount(length);
}

Expand Down
52 changes: 27 additions & 25 deletions java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,32 +261,34 @@ public void splitAndTransferTo(int startIndex, int length, BitVector target) {
int firstByte = getByteIndex(startIndex);
int byteSize = getSizeFromCount(length);
int offset = startIndex % 8;
if (offset == 0) {
target.clear();
// slice
if (target.data != null) {
target.data.release();
}
target.data = data.slice(firstByte, byteSize);
target.data.retain(1);
} else {
// Copy data
// When the first bit starts from the middle of a byte (offset != 0), copy data from src BitVector.
// Each byte in the target is composed by a part in i-th byte, another part in (i+1)-th byte.
// The last byte copied to target is a bit tricky :
// 1) if length requires partly byte (length % 8 !=0), copy the remaining bits only.
// 2) otherwise, copy the last byte in the same way as to the prior bytes.
target.clear();
target.allocateNew(length);
// TODO maybe do this one word at a time, rather than byte?
for(int i = 0; i < byteSize - 1; i++) {
target.data.setByte(i, (((this.data.getByte(firstByte + i) & 0xFF) >>> offset) + (this.data.getByte(firstByte + i + 1) << (8 - offset))));
}
if (length % 8 != 0) {
target.data.setByte(byteSize - 1, ((this.data.getByte(firstByte + byteSize - 1) & 0xFF) >>> offset));
if (length > 0) {
if (offset == 0) {
target.clear();
// slice
if (target.data != null) {
target.data.release();
}
target.data = data.slice(firstByte, byteSize);
target.data.retain(1);
} else {
target.data.setByte(byteSize - 1,
(((this.data.getByte(firstByte + byteSize - 1) & 0xFF) >>> offset) + (this.data.getByte(firstByte + byteSize) << (8 - offset))));
// Copy data
// When the first bit starts from the middle of a byte (offset != 0), copy data from src BitVector.
// Each byte in the target is composed by a part in i-th byte, another part in (i+1)-th byte.
// The last byte copied to target is a bit tricky :
// 1) if length requires partly byte (length % 8 !=0), copy the remaining bits only.
// 2) otherwise, copy the last byte in the same way as to the prior bytes.
target.clear();
target.allocateNew(length);
// TODO maybe do this one word at a time, rather than byte?
for (int i = 0; i < byteSize - 1; i++) {
target.data.setByte(i, (((this.data.getByte(firstByte + i) & 0xFF) >>> offset) + (this.data.getByte(firstByte + i + 1) << (8 - offset))));
}
if (length % 8 != 0) {
target.data.setByte(byteSize - 1, ((this.data.getByte(firstByte + byteSize - 1) & 0xFF) >>> offset));
} else {
target.data.setByte(byteSize - 1,
(((this.data.getByte(firstByte + byteSize - 1) & 0xFF) >>> offset) + (this.data.getByte(firstByte + byteSize) << (8 - offset))));
}
}
}
target.getMutator().setValueCount(length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.UInt4Vector;
import org.apache.arrow.vector.ValueVector;
import org.apache.arrow.vector.VarCharVector;
import org.apache.arrow.vector.ZeroVector;
import org.apache.arrow.vector.complex.impl.ComplexCopier;
import org.apache.arrow.vector.complex.impl.UnionListReader;
Expand Down Expand Up @@ -179,7 +180,11 @@ public TransferPair makeTransferPair(ValueVector target) {
private class TransferImpl implements TransferPair {

ListVector to;
TransferPair pairs[] = new TransferPair[3];
TransferPair bitsTransferPair;
TransferPair offsetsTransferPair;
TransferPair dataTransferPair;

TransferPair[] pairs;

public TransferImpl(String name, BufferAllocator allocator, CallBack callBack) {
this(new ListVector(name, allocator, fieldType, callBack));
Expand All @@ -188,12 +193,13 @@ public TransferImpl(String name, BufferAllocator allocator, CallBack callBack) {
public TransferImpl(ListVector to) {
this.to = to;
to.addOrGetVector(vector.getField().getFieldType());
pairs[0] = offsets.makeTransferPair(to.offsets);
pairs[1] = bits.makeTransferPair(to.bits);
offsetsTransferPair = offsets.makeTransferPair(to.offsets);
bitsTransferPair = bits.makeTransferPair(to.bits);
if (to.getDataVector() instanceof ZeroVector) {
to.addOrGetVector(vector.getField().getFieldType());
}
pairs[2] = getDataVector().makeTransferPair(to.getDataVector());
dataTransferPair = getDataVector().makeTransferPair(to.getDataVector());
pairs = new TransferPair[] { bitsTransferPair, offsetsTransferPair, dataTransferPair };
}

@Override
Expand All @@ -206,10 +212,20 @@ public void transfer() {

@Override
public void splitAndTransfer(int startIndex, int length) {
to.allocateNew();
for (int i = 0; i < length; i++) {
copyValueSafe(startIndex + i, i);
UInt4Vector.Accessor offsetVectorAccessor = ListVector.this.offsets.getAccessor();
final int startPoint = offsetVectorAccessor.get(startIndex);
final int sliceLength = offsetVectorAccessor.get(startIndex + length) - startPoint;
to.clear();
to.offsets.allocateNew(length + 1);
offsetVectorAccessor = ListVector.this.offsets.getAccessor();
final UInt4Vector.Mutator targetOffsetVectorMutator = to.offsets.getMutator();
for (int i = 0; i < length + 1; i++) {
targetOffsetVectorMutator.set(i, offsetVectorAccessor.get(startIndex + i) - startPoint);
}
bitsTransferPair.splitAndTransfer(startIndex, length);
dataTransferPair.splitAndTransfer(startPoint, sliceLength);
to.lastSet = length;
to.mutator.setValueCount(length);
}

@Override
Expand Down