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

UnionListWriter.list() is doing more than it should, this can cause data corruption

    Details

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

      Description

      If you run the following code:

          MapVector parent = new MapVector("parent", allocator, null);
          ComplexWriter writer = new ComplexWriterImpl("root", parent);
          MapWriter rootWriter = writer.rootAsMap();
      
          ListWriter listWriter = rootWriter.list("list");
          ListWriter list = listWriter.list();
      
          rootWriter.start();
          {
            listWriter.startList();
            {
              list.startList();
              list.bigInt().writeBigInt(0);
              list.endList();
            }
            {
              list.startList();
              list.bigInt().writeBigInt(1);
              list.endList();
            }
            listWriter.endList();
          }
          rootWriter.end();
      
          writer.setValueCount(1);
      
          MapReader rootReader = new SingleMapReaderImpl(parent).reader("root");
      
          System.out.println(rootReader.reader("list").readObject());
      

      You should expect it to print

      [[0],[1]]

      but it actually prints

      [[0,1]]

      If you change the code so that UnionListWriter.list() is called along with startList() then the code works fine:

          MapVector parent = new MapVector("parent", allocator, null);
          ComplexWriter writer = new ComplexWriterImpl("root", parent);
          MapWriter rootWriter = writer.rootAsMap();
      
          rootWriter.start();
          {
            ListWriter listWriter = rootWriter.list("mylist");
            listWriter.startList();
            {
              ListWriter list = listWriter.list();
              list.startList();
              list.bigInt().writeBigInt(0);
              list.endList();
            }
            {
              ListWriter list = listWriter.list();
              list.startList();
              list.bigInt().writeBigInt(1);
              list.endList();
            }
            listWriter.endList();
          }
          rootWriter.end();
      
          writer.setValueCount(1);
      
          MapReader rootReader = new SingleMapReaderImpl(parent).reader("root");
      
          System.out.println(rootReader.reader("mylist").readObject());
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: