Skip to content

Commit 31e95e6

Browse files
committed
fix list vector
1 parent b824938 commit 31e95e6

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

java/vector/src/main/java/org/apache/arrow/vector/VectorLoader.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,37 @@
2929
import org.apache.arrow.vector.types.pojo.Field;
3030
import org.apache.arrow.vector.types.pojo.Schema;
3131

32+
import com.google.common.collect.Iterators;
33+
3234
import io.netty.buffer.ArrowBuf;
3335

36+
/**
37+
* Loads buffers into vectors
38+
*/
3439
public class VectorLoader {
3540
private final List<FieldVector> fieldVectors;
3641
private final List<Field> fields;
3742

43+
/**
44+
* will create children in root based on schema
45+
* @param schema the expected schema
46+
* @param root the root to add vectors to based on schema
47+
*/
3848
public VectorLoader(Schema schema, FieldVector root) {
3949
super();
4050
this.fields = schema.getFields();
4151
root.initializeChildrenFromFields(fields);
4252
this.fieldVectors = root.getChildrenFromFields();
4353
if (this.fieldVectors.size() != fields.size()) {
44-
throw new IllegalArgumentException(); //TODO
54+
throw new IllegalArgumentException("The root vector did not create the right number of children. found " + fieldVectors.size() + " expected " + fields.size());
4555
}
4656
}
4757

58+
/**
59+
* Loads the record batch in the vectors
60+
* will not close the record batch
61+
* @param recordBatch
62+
*/
4863
public void load(ArrowRecordBatch recordBatch) {
4964
Iterator<ArrowBuf> buffers = recordBatch.getBuffers().iterator();
5065
Iterator<ArrowFieldNode> nodes = recordBatch.getNodes().iterator();
@@ -53,6 +68,9 @@ public void load(ArrowRecordBatch recordBatch) {
5368
FieldVector fieldVector = fieldVectors.get(i);
5469
loadBuffers(fieldVector, field, buffers, nodes);
5570
}
71+
if (nodes.hasNext() || buffers.hasNext()) {
72+
throw new IllegalArgumentException("not all nodes and buffers where consumed. nodes: " + Iterators.toString(nodes) + " buffers: " + Iterators.toString(buffers));
73+
}
5674
}
5775

5876
private void loadBuffers(FieldVector vector, Field field, Iterator<ArrowBuf> buffers, Iterator<ArrowFieldNode> nodes) {

java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
public class ListVector extends BaseRepeatedValueVector implements FieldVector {
5353

54-
UInt4Vector offsets;// TODO: THis masks the same vector in the parent
54+
final UInt4Vector offsets;// TODO: THis masks the same vector in the parent which is assigned to this in the constructor.
5555
final UInt1Vector bits;
5656
private Mutator mutator = new Mutator();
5757
private Accessor accessor = new Accessor();
@@ -62,7 +62,7 @@ public class ListVector extends BaseRepeatedValueVector implements FieldVector {
6262
public ListVector(String name, BufferAllocator allocator, CallBack callBack) {
6363
super(name, allocator);
6464
this.bits = new UInt1Vector("$bits$", allocator);
65-
offsets = getOffsetVector();
65+
this.offsets = getOffsetVector();
6666
this.writer = new UnionListWriter(this);
6767
this.reader = new UnionListReader(this);
6868
this.callBack = callBack;
@@ -92,7 +92,7 @@ public void loadFieldBuffers(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers
9292
throw new IllegalArgumentException("Lists have a validity and offset vector. Found: " + ownBuffers);
9393
}
9494
this.bits.load(ownBuffers.get(0));
95-
this.offsets.load(ownBuffers.get(0));
95+
this.offsets.load(ownBuffers.get(1));
9696
}
9797

9898
@Override

0 commit comments

Comments
 (0)