Skip to content

Commit

Permalink
add Java unit tests for making list of list (#8111)
Browse files Browse the repository at this point in the history
This PR is trying to add java binding support for making List of List based on #8046. But the existing jni API makeList has already supported to create List of List, this PR just add unit tests for making list of list.

Authors:
  - Bobby Wang (https://github.com/wbo4958)

Approvers:
  - Jason Lowe (https://github.com/jlowe)

URL: #8111
  • Loading branch information
wbo4958 authored May 6, 2021
1 parent 611cabd commit 96c0706
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4342,37 +4342,64 @@ void testMakeStruct() {

@Test
void testMakeListEmpty() {
final int numRows = 10;
try (ColumnVector expected =
final int numRows = 4;
List<List<String>> emptyListOfList = new ArrayList<>();
emptyListOfList.add(Arrays.asList());
try (
ColumnVector expectedList =
ColumnVector.fromLists(
new ListType(false, new BasicType(false, DType.STRING)),
Arrays.asList(),
Arrays.asList(),
Arrays.asList(),
Arrays.asList(),
Arrays.asList(),
Arrays.asList(),
Arrays.asList(),
Arrays.asList(),
Arrays.asList(),
Arrays.asList());
ColumnVector created = ColumnVector.makeList(numRows, DType.STRING)) {
assertColumnsAreEqual(expected, created);
ColumnVector expectedListOfList = ColumnVector.fromLists(new HostColumnVector.ListType(false,
new HostColumnVector.ListType(false,
new HostColumnVector.BasicType(false, DType.STRING))),
emptyListOfList, emptyListOfList, emptyListOfList, emptyListOfList);

ColumnVector createdList = ColumnVector.makeList(numRows, DType.STRING);
ColumnVector createdListOfList = ColumnVector.makeList(createdList)) {
assertColumnsAreEqual(expectedList, createdList);
assertColumnsAreEqual(expectedListOfList, createdListOfList);
}
}

@Test
void testMakeList() {
try (ColumnVector expected =
ColumnVector.fromLists(
new ListType(false, new BasicType(false, DType.INT32)),
Arrays.asList(1, 3, 5),
Arrays.asList(2, 4, 6));
List<Integer> list1 = Arrays.asList(1, 3);
List<Integer> list2 = Arrays.asList(2, 4);
List<Integer> list3 = Arrays.asList(5, 7, 9);
List<Integer> list4 = Arrays.asList(6, 8, 10);
List<List<Integer>> mainList1 = new ArrayList<>(Arrays.asList(list1, list3));
List<List<Integer>> mainList2 = new ArrayList<>(Arrays.asList(list2, list4));
try (ColumnVector expectedList1 =
ColumnVector.fromLists(new ListType(false,
new BasicType(false, DType.INT32)), list1, list2);
ColumnVector expectedList2 =
ColumnVector.fromLists(new ListType(false,
new BasicType(false, DType.INT32)), list3, list4);
ColumnVector expectedListOfList = ColumnVector.fromLists(new HostColumnVector.ListType(true,
new HostColumnVector.ListType(true, new HostColumnVector.BasicType(true, DType.INT32))),
mainList1, mainList2);
ColumnVector child1 = ColumnVector.fromInts(1, 2);
ColumnVector child2 = ColumnVector.fromInts(3, 4);
ColumnVector child3 = ColumnVector.fromInts(5, 6);
ColumnVector created = ColumnVector.makeList(child1, child2, child3)) {
assertColumnsAreEqual(expected, created);
ColumnVector child4 = ColumnVector.fromInts(7, 8);
ColumnVector child5 = ColumnVector.fromInts(9, 10);
ColumnVector createdList1 = ColumnVector.makeList(child1, child2);
ColumnVector createdList2 = ColumnVector.makeList(child3, child4, child5);
ColumnVector createdListOfList = ColumnVector.makeList(createdList1, createdList2);
HostColumnVector hcv = createdListOfList.copyToHost()) {

assertColumnsAreEqual(expectedList1, createdList1);
assertColumnsAreEqual(expectedList2, createdList2);
assertColumnsAreEqual(expectedListOfList, createdListOfList);

List<List<Integer>> ret1 = hcv.getList(0);
List<List<Integer>> ret2 = hcv.getList(1);
assertEquals(mainList1, ret1, "Lists don't match");
assertEquals(mainList2, ret2, "Lists don't match");
}
}

Expand Down

0 comments on commit 96c0706

Please sign in to comment.