Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-308

UnionListWriter.setPosition() should not call startList()

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.1.0
    • Component/s: Java
    • Labels:
      None

      Description

      UnionListWriter.setPosition() is implemented as follows:

        @Override
        public void setPosition(int index) {
          super.setPosition(index);
          startList();
        }
      

      It works fine, but if you run the following 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());
          }
      

      You get:

      0: {"root":{"int":0,"list":[0]}}
      1: {"root":{"int":1,"list":[]}}
      2: {"root":{"int":2,"list":[2]}}
      

      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.

        Attachments

          Activity

            People

            • Assignee:
              adeneche Deneche A. Hakim
              Reporter:
              adeneche Deneche A. Hakim
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: