Skip to content

Commit

Permalink
ARROW-6175: [Java] Fix MapVector#getMinorType and extend AbstractCont…
Browse files Browse the repository at this point in the history
…ainerVector addOrGet complex vector API

Related to [ARROW-6175](https://issues.apache.org/jira/browse/ARROW-6175).

i. Currently MapVector#getMinorType extends ListVector which returns the wrong MinorType.
ii. AbstractContainerVector now only has addOrGetList, addOrGetUnion, addOrGetStruct which not support all complex type like MapVector and FixedSizeListVector.

Closes #5043 from tianchen92/ARROW-6175 and squashes the following commits:

110aa84 <tianchen> ARROW-XXXX: Fix MapVector#getMinorType and extend AbstractContainerVector addOrGet complex vector API

Authored-by: tianchen <niki.lj@alibaba-inc.com>
Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
  • Loading branch information
tianchen92 authored and emkornfield committed Aug 10, 2019
1 parent b98a560 commit 6006a7d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.ValueVector;
import org.apache.arrow.vector.types.Types.MinorType;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.ArrowType.FixedSizeList;
import org.apache.arrow.vector.types.pojo.ArrowType.List;
import org.apache.arrow.vector.types.pojo.ArrowType.Struct;
import org.apache.arrow.vector.types.pojo.FieldType;
Expand Down Expand Up @@ -113,6 +115,14 @@ public UnionVector addOrGetUnion(String name) {
return addOrGet(name, FieldType.nullable(MinorType.UNION.getType()), UnionVector.class);
}

public FixedSizeListVector addOrGetFixedSizeList(String name, int listSize) {
return addOrGet(name, FieldType.nullable(new FixedSizeList(listSize)), FixedSizeListVector.class);
}

public MapVector addOrGetMap(String name, boolean keysSorted) {
return addOrGet(name, FieldType.nullable(new ArrowType.Map(keysSorted)), MapVector.class);
}

@Override
public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ public UnionMapReader getReader() {
}
return (UnionMapReader)reader;
}

@Override
public MinorType getMinorType() {
return MinorType.MAP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,4 @@ public interface RepeatedFixedWidthVectorLike {
* @param innerValueCount Number of supported values in the vector.
*/
void allocateNew(int valueCount, int innerValueCount);

/**
* Load the records in the provided buffer based on the given number of values.
* @param valueCount Number of separate repeating groupings.
* @param innerValueCount Number atomic values the buffer contains.
* @param buf Incoming buffer.
* @return The number of bytes of the buffer that were consumed.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,25 @@ public void testGetPrimitiveVectors() {
assertEquals(MinorType.VARCHAR, primitiveVectors.get(3).getMinorType());
}
}

@Test
public void testAddOrGetComplexChildVectors() {
FieldType type = new FieldType(true, Struct.INSTANCE, null, null);
try (StructVector vector = new StructVector("struct", allocator, type, null)) {

vector.addOrGetList("list");
vector.addOrGetFixedSizeList("fixedList", 2);
vector.addOrGetUnion("union");
vector.addOrGetStruct("struct");
vector.addOrGetMap("map", true);

List<FieldVector> childrens = vector.getChildrenFromFields();
assertEquals(5, childrens.size());
assertEquals(MinorType.LIST, childrens.get(0).getMinorType());
assertEquals(MinorType.FIXED_SIZE_LIST, childrens.get(1).getMinorType());
assertEquals(MinorType.UNION, childrens.get(2).getMinorType());
assertEquals(MinorType.STRUCT, childrens.get(3).getMinorType());
assertEquals(MinorType.MAP, childrens.get(4).getMinorType());
}
}
}

0 comments on commit 6006a7d

Please sign in to comment.