Skip to content

Commit

Permalink
fix: adding test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed Jul 10, 2024
1 parent e751d93 commit 36e13be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,17 +579,20 @@ public void validateUnionData(int count, VectorSchemaRoot root) {
FieldReader unionReader = root.getVector("union").getReader();
for (int i = 0; i < count; i++) {
unionReader.setPosition(i);
switch (i % 4) {
switch (i % 5) {
case 0:
assertEquals(i, unionReader.readInteger().intValue());
break;
case 1:
assertEquals(i, unionReader.readLong().longValue());
break;
case 2:
assertEquals(i % 3 * 2, unionReader.size());
assertEquals(i % 3, unionReader.size());
break;
case 3:
// assertEquals(i % 4, unionReader.size());
break;
case 4:
NullableTimeStampMilliHolder h = new NullableTimeStampMilliHolder();
unionReader.reader("timestamp").read(h);
assertEquals(i, h.value);
Expand All @@ -615,7 +618,7 @@ public void writeUnionData(int count, StructVector parent) {
ListWriter listViewWriter = rootWriter.listView("union");
StructWriter structWriter = rootWriter.struct("union");
for (int i = 0; i < count; i++) {
switch (i % 4) {
switch (i % 5) {
case 0:
intWriter.setPosition(i);
intWriter.writeInt(i);
Expand All @@ -627,16 +630,20 @@ public void writeUnionData(int count, StructVector parent) {
case 2:
listWriter.setPosition(i);
listWriter.startList();
listViewWriter.setPosition(i);
listViewWriter.startListView();
for (int j = 0; j < i % 3; j++) {
listViewWriter.varChar().writeVarChar(0, 3, varchar);
listWriter.varChar().writeVarChar(0, 3, varchar);
}
listWriter.endList();
listViewWriter.endListView();
break;
case 3:
listViewWriter.setPosition(i);
listViewWriter.startListView();
for (int j = 0; j < i % 5; j++) {
listViewWriter.varChar().writeVarChar(0, 3, varchar);
}
listViewWriter.endListView();
break;
case 4:
structWriter.setPosition(i);
structWriter.start();
structWriter.timeStampMilli("timestamp").writeTimeStampMilli(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.complex.ListViewVector;
import org.apache.arrow.vector.complex.StructVector;
import org.apache.arrow.vector.complex.impl.ComplexWriterImpl;
import org.apache.arrow.vector.complex.writer.BaseWriter;
Expand Down Expand Up @@ -154,12 +153,6 @@ public void writeJSON(File file, VectorSchemaRoot root, DictionaryProvider provi

@Test
public void testWriteReadUnionJSON() throws IOException {
/*
* TODO: UnionWriter varChar() -> Also forwards with MinorType.LIST
PromotableWriter varChar() -> Also forwards with MinorType.LIST
Because of this we cannot actually create a ListViewVector.
We need to fix this first.
* */
File file = new File("target/mytest_write_union.json");
int count = COUNT;
try (BufferAllocator vectorAllocator =
Expand All @@ -169,8 +162,6 @@ PromotableWriter varChar() -> Also forwards with MinorType.LIST
printVectors(parent.getChildrenFromFields());

try (VectorSchemaRoot root = new VectorSchemaRoot(parent.getChild("root"))) {
ListViewVector vec =
(ListViewVector) root.getFieldVectors().get(0).getChildrenFromFields().get(3);
validateUnionData(count, root);
writeJSON(file, root, null);

Expand Down

0 comments on commit 36e13be

Please sign in to comment.