Skip to content
Open
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 @@ -54,6 +54,7 @@ public class VectorSchemaRoot implements AutoCloseable {
private int rowCount;
private final List<FieldVector> fieldVectors;
private final Map<Field, FieldVector> fieldVectorsMap = new LinkedHashMap<>();
private final Map<String, FieldVector> fieldVectorsByName = new LinkedHashMap<>();

/** Constructs new instance containing each of the vectors. */
public VectorSchemaRoot(Iterable<FieldVector> vectors) {
Expand Down Expand Up @@ -116,6 +117,7 @@ public VectorSchemaRoot(Schema schema, List<FieldVector> fieldVectors, int rowCo
Field field = schema.getFields().get(i);
FieldVector vector = fieldVectors.get(i);
fieldVectorsMap.put(field, vector);
fieldVectorsByName.putIfAbsent(field.getName(), vector);
}
}

Expand Down Expand Up @@ -173,12 +175,7 @@ public List<FieldVector> getFieldVectors() {
* <p>if name occurs multiple times this returns the first inserted entry for name
*/
public FieldVector getVector(String name) {
for (Map.Entry<Field, FieldVector> entry : fieldVectorsMap.entrySet()) {
if (entry.getKey().getName().equals(name)) {
return entry.getValue();
}
}
return null;
return fieldVectorsByName.get(name);
}

public FieldVector getVector(Field field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -90,6 +91,17 @@ private void checkCount(BitVector vec1, IntVector vec2, VectorSchemaRoot vsr, in
assertEquals(vsr.getRowCount(), count);
}

@Test
public void testGetVectorByName() {
try (IntVector intVector = new IntVector("intVector", allocator);
BitVector bitVector = new BitVector("bitVector", allocator);
VectorSchemaRoot root = VectorSchemaRoot.of(intVector, bitVector)) {
assertEquals(intVector, root.getVector("intVector"));
assertEquals(bitVector, root.getVector("bitVector"));
assertNull(root.getVector("missingVector"));
}
}

private VectorSchemaRoot createBatch() {
FieldType varCharType = new FieldType(true, new ArrowType.Utf8(), /* dictionary= */ null);
FieldType listType = new FieldType(true, new ArrowType.List(), /* dictionary= */ null);
Expand Down
Loading