[ 
https://issues.apache.org/jira/browse/ARROW-308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17657342#comment-17657342
 ] 

Rok Mihevc commented on ARROW-308:
----------------------------------

This issue has been migrated to [issue 
#15730|https://github.com/apache/arrow/issues/15730] on GitHub. Please see the 
[migration documentation|https://github.com/apache/arrow/issues/14542] for 
further details.

> UnionListWriter.setPosition() should not call startList()
> ---------------------------------------------------------
>
>                 Key: ARROW-308
>                 URL: https://issues.apache.org/jira/browse/ARROW-308
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Java
>            Reporter: Abdel Hakim Deneche
>            Assignee: Abdel Hakim Deneche
>            Priority: Major
>             Fix For: 0.1.0
>
>
> UnionListWriter.setPosition() is implemented as follows:
> {code}
>   @Override
>   public void setPosition(int index) {
>     super.setPosition(index);
>     startList();
>   }
> {code}
> It works fine, but if you run the following code:
> {code}
>     MapVector parent = new MapVector("parent", allocator, null);
>     ComplexWriter writer = new ComplexWriterImpl("root", parent);
>     MapWriter rootWriter = writer.rootAsMap();
>     rootWriter.start();
>     rootWriter.bigInt("int").writeBigInt(0);
>     rootWriter.list("list").startList();
>     rootWriter.list("list").bigInt().writeBigInt(0);
>     rootWriter.list("list").endList();
>     rootWriter.end();
>     rootWriter.setPosition(1);
>     rootWriter.start();
>     rootWriter.bigInt("int").writeBigInt(1);
>     rootWriter.end();
>     rootWriter.setPosition(2);
>     rootWriter.bigInt("int").writeBigInt(2);
>     rootWriter.start();
>     rootWriter.list("list").startList();
>     rootWriter.list("list").bigInt().writeBigInt(2);
>     rootWriter.list("list").endList();
>     rootWriter.end();
>     writer.setValueCount(3);
>     for (int i = 0; i < 3; i++) {
>       parent.getReader().setPosition(i);
>       System.out.printf("%d: %s%n", i, parent.getReader().readObject());
>     }
> {code}
> You get:
> {noformat}
> 0: {"root":{"int":0,"list":[0]}}
> 1: {"root":{"int":1,"list":[]}}
> 2: {"root":{"int":2,"list":[2]}}
> {noformat}
> Even though we didn't write anything in the 2nd row "list", it shows up as 
> empty instead of null. I tracked the problem to UnionListWriter.setPosition() 
> calling startList() which marks the row as not null even if we don't write 
> anything to it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to