From user-return-999-archive-asf-public=cust-asf.ponee.io@arrow.apache.org Tue Feb 16 17:31:17 2021 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-he-de.apache.org (mxout1-he-de.apache.org [95.216.194.37]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id D22F8180686 for ; Tue, 16 Feb 2021 18:31:17 +0100 (CET) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-he-de.apache.org (ASF Mail Server at mxout1-he-de.apache.org) with SMTP id 77EE864756 for ; Tue, 16 Feb 2021 17:31:16 +0000 (UTC) Received: (qmail 17624 invoked by uid 500); 16 Feb 2021 17:31:14 -0000 Mailing-List: contact user-help@arrow.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@arrow.apache.org Delivered-To: mailing list user@arrow.apache.org Received: (qmail 17609 invoked by uid 99); 16 Feb 2021 17:31:14 -0000 Received: from ec2-52-204-25-47.compute-1.amazonaws.com (HELO mailrelay1-ec2-va.apache.org) (52.204.25.47) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Feb 2021 17:31:14 +0000 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by mailrelay1-ec2-va.apache.org (ASF Mail Server at mailrelay1-ec2-va.apache.org) with ESMTPSA id 9F2214221D for ; Tue, 16 Feb 2021 17:31:14 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id o38so6658421pgm.9 for ; Tue, 16 Feb 2021 09:31:14 -0800 (PST) X-Gm-Message-State: AOAM530pF9niM+avKhOu8d6ltjMUkWswaUYq7pjjzlO9SlzZc9LlK9/m 8OaUEXN3+v/uHtErLWi/l0942SoxnR60bvENGZM= X-Google-Smtp-Source: ABdhPJyAOAB5b8o22ChphB6l3EFZcNn1w2K/eEApzVLQ+uzvSXW3pSFvYoYiLL0e/NArDtVsfDQnnTXsaNRLZGCkPBo= X-Received: by 2002:aa7:8286:0:b029:1e2:70ef:c410 with SMTP id s6-20020aa782860000b02901e270efc410mr20086316pfm.45.1613496673990; Tue, 16 Feb 2021 09:31:13 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jacques Nadeau Date: Tue, 16 Feb 2021 09:31:02 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [Java] Flight fails to handle list vector To: user@arrow.apache.org Content-Type: multipart/alternative; boundary="000000000000197f7e05bb77787e" --000000000000197f7e05bb77787e Content-Type: text/plain; charset="UTF-8" Hey John, a brief review of your code makes me wonder if the problem may be associated with VectorSchemaRootAppender. Can you try your test without that. Basically, once you get a batch of data back, inspect it to see that you have your values. VectorSchemaRootAppender is new code that I haven't reviewed and I'm wondering if it isn't handling reference counting correctly. The exception you're seeing is most frequently associated with what could be thought of as a NPE for the memory backing a vector. When a vectors are like a container. The design was built so a vector has batches stream through it. When no buffer is available, rather than setting the buffer to null, we set it to the empty buffer (which is of zero length). If you try to do something with the vector when it is empty. In this case, my guess is you are trying to read the start offset for the first item in a list e.g. the first four bytes [0..4) of the vector but the vector is only 0 bytes in length (thus the exception). On Mon, Feb 15, 2021 at 7:21 PM John Peterson wrote: > Appreciate the help Jacques. Unfortunately calling setPosition(0) on the > writer for the list did not solve it. > > I put the entirety of the code up on pastebin so it should be an easy > copy/paste if anybody else wants to try to reproduce it. I suppose it could > also be a bug in VectorAppender, but again I'm not sure if the error is in > my code or in Arrow. > > https://pastebin.com/vwvnYY40 > > Thanks in advance. > > > On Mon, Feb 15, 2021 at 1:33 PM Jacques Nadeau wrote: > >> I think you need to call setPosition(0) before you start writing the >> list. (This is from memory when I wrote the code 6-7 years ago so I may be >> off.) >> >> On Sun, Feb 14, 2021 at 6:20 PM John Peterson < >> donttrytocontactme2@gmail.com> wrote: >> >>> Hi Bryan, >>> >>> This is the stacktrace I get: >>> >>> java.lang.IndexOutOfBoundsException: index: 0, length: 4 (expected: >>> range(0, 0)) >>> at org.apache.arrow.memory.ArrowBuf.checkIndexD(ArrowBuf.java:318) >>> at org.apache.arrow.memory.ArrowBuf.chk(ArrowBuf.java:305) >>> at org.apache.arrow.memory.ArrowBuf.getInt(ArrowBuf.java:424) >>> at >>> org.apache.arrow.vector.util.VectorAppender.visit(VectorAppender.java:97) >>> at >>> org.apache.arrow.vector.util.VectorAppender.visit(VectorAppender.java:45) >>> at >>> org.apache.arrow.vector.BaseVariableWidthVector.accept(BaseVariableWidthVector.java:1402) >>> at >>> org.apache.arrow.vector.util.VectorAppender.visit(VectorAppender.java:233) >>> at >>> org.apache.arrow.vector.util.VectorAppender.visit(VectorAppender.java:45) >>> at org.apache.arrow.vector.complex.ListVector.accept(ListVector.java:449) >>> at >>> org.apache.arrow.vector.util.VectorSchemaRootAppender.append(VectorSchemaRootAppender.java:67) >>> at >>> org.apache.arrow.vector.util.VectorSchemaRootAppender.append(VectorSchemaRootAppender.java:81) >>> >>> Thanks for your help. >>> >>> On Thu, Jan 14, 2021 at 2:23 PM Bryan Cutler wrote: >>> >>>> Hi John, could you include the error with stacktrace? >>>> >>>> On Sat, Jan 9, 2021 at 9:34 PM John Peterson < >>>> donttrytocontactme2@gmail.com> wrote: >>>> >>>>> I believe I'm running into a bug with Flight but I'd like to confirm >>>>> and get some advice on a potential fix. I'm not sure where to look or what >>>>> could be causing it. >>>>> >>>>> The code in question simply uploads a one-element List to the >>>>> example server, fetches it from the server, and attempts to append the data >>>>> from the server to a new VectorSchemaRoot. It fails in the same way >>>>> regardless of whether or not I construct a VectorSchemaRoot instance. >>>>> >>>>> Likewise, the data from the server can't be written out with the JSON >>>>> writer, it'll fail in the same way. However, changing the data from a >>>>> ListVector to an IntVector causes it to succeed. >>>>> >>>>> Any help would be appreciated. >>>>> >>>>> Thanks, >>>>> John >>>>> >>>>> Code in question: >>>>> // Set up the server and client >>>>> BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); >>>>> Location l = Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, 12233); >>>>> ExampleFlightServer server = new ExampleFlightServer(allocator, l); >>>>> server.start(); >>>>> FlightClient client = FlightClient.builder(allocator, l).build(); >>>>> >>>>> // Write a one-element List >>>>> ListVector listVector = ListVector.empty("list", allocator); >>>>> UnionListWriter writer = listVector.getWriter(); >>>>> writer.startList(); >>>>> writer.integer().writeInt(1); >>>>> writer.endList(); >>>>> writer.setValueCount(1); >>>>> >>>>> // Send that data to the server >>>>> VectorSchemaRoot root = VectorSchemaRoot.of(listVector); >>>>> ClientStreamListener listener = >>>>> client.startPut(FlightDescriptor.path("test"), root, new >>>>> AsyncPutListener()); >>>>> root.setRowCount(1); >>>>> listener.putNext(); >>>>> root.clear(); >>>>> listener.completed(); >>>>> >>>>> // wait for ack to avoid memory leaks. >>>>> listener.getResult(); >>>>> >>>>> // Attempt to read it back >>>>> FlightInfo info = client.getInfo(FlightDescriptor.path("test")); >>>>> try (final FlightStream stream = >>>>> client.getStream(info.getEndpoints().get(0).getTicket())) { >>>>> VectorSchemaRoot newRoot = stream.getRoot(); >>>>> while (stream.next()) { >>>>> // Copying into an entirely new VectorSchemaRoot fails >>>>> try { >>>>> ListVector newList = ListVector.empty("list", allocator); >>>>> >>>>> newList.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())); >>>>> VectorSchemaRoot copyRoot = VectorSchemaRoot.of(newList); >>>>> VectorSchemaRootAppender.append(copyRoot, newRoot); >>>>> } catch (IndexOutOfBoundsException e) { >>>>> System.err.println("Expected IOOBE caught"); >>>>> } >>>>> >>>>> // The same is true if we try to copy the data from the server to >>>>> our VectorSchemaRoot >>>>> try { >>>>> VectorSchemaRootAppender.append(root, newRoot); >>>>> } catch (IndexOutOfBoundsException e) { >>>>> System.err.println("Expected IOOBE caught again"); >>>>> throw e; >>>>> } >>>>> >>>>> root.clear(); >>>>> newRoot.clear(); >>>>> } >>>>> } >>>>> >>>> --000000000000197f7e05bb77787e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hey John, a brief review of your code makes me wonder if t= he problem may be associated with VectorSchemaRootAppender. Can you try you= r test without that. Basically, once you get a batch of data back, inspect = it to see that you have your values. VectorSchemaRootAppender is new code t= hat I haven't reviewed and I'm wondering if it isn't handling r= eference counting correctly.=C2=A0

The exception you'= ;re seeing is most frequently associated with what could be thought of as a= NPE for the memory backing a vector. When a vectors are like a container. = The design was built so a vector has batches stream through it. When no buf= fer is available, rather than setting the buffer to null, we set it to the = empty buffer (which is of zero length). If you try to do something=C2=A0wit= h the vector when it is empty. In this case, my guess is you are trying to = read the start offset for the first item in a list e.g. the first four byte= s [0..4) of the vector but the vector is only 0 bytes in length (thus the e= xception).

On Mon, Feb 15, 2021 at 7:21 PM John Peterson <donttrytocontactme2@gmail.com= > wrote:
Appreciate the help Jacques. Unfortunately calling setPosition= (0) on the writer for the list did not solve it.

I put t= he entirety of the code up on pastebin so it should be an easy copy/paste i= f anybody else wants to try to reproduce it. I suppose it could also be a b= ug in VectorAppender, but again I'm not sure if the error is in my code= or in Arrow.

Thanks in advance.


On Mon, Feb 15, 2021 at = 1:33 PM Jacques Nadeau <jacques@apache.org> wrote:
I think you need to call setPosi= tion(0) before you start writing the list. (This is from memory when I wrot= e the code 6-7 years ago so I may be off.)

On Sun, Feb 14, 2021 at 6:20 = PM John Peterson <donttrytocontactme2@gmail.com> wrote:
Hi Bryan,

This is the stacktrace=C2=A0I get:
=
java.lang.IndexOutOfBoundsException: index: 0, length: 4 (ex= pected: range(0, 0))
at org.apache.arrow.memory.ArrowBuf.checkIndexD(Ar= rowBuf.java:318)
at org.apache.arrow.memory.ArrowBuf.chk(ArrowBuf.java:= 305)
at org.apache.arrow.memory.ArrowBuf.getInt(ArrowBuf.java:424)
= at org.apache.arrow.vector.util.VectorAppender.visit(VectorAppender.java:97= )
at org.apache.arrow.vector.util.VectorAppender.visit(VectorAppender.j= ava:45)
at org.apache.arrow.vector.BaseVariableWidthVector.accept(BaseV= ariableWidthVector.java:1402)
at org.apache.arrow.vector.util.VectorApp= ender.visit(VectorAppender.java:233)
at org.apache.arrow.vector.util.Ve= ctorAppender.visit(VectorAppender.java:45)
at org.apache.arrow.vector.c= omplex.ListVector.accept(ListVector.java:449)
at org.apache.arrow.vecto= r.util.VectorSchemaRootAppender.append(VectorSchemaRootAppender.java:67) at org.apache.arrow.vector.util.VectorSchemaRootAppender.append(VectorSch= emaRootAppender.java:81)

Thanks fo= r your help.

On Thu, Jan 14, 2021 at 2:23 PM Bryan Cutler <cutlerb@gmail.com> wrote:
<= div style=3D"font-family:verdana,sans-serif">Hi John, could you include the= error with stacktrace?

On Sat, Jan 9, 2021 at 9:34 PM John Peters= on <d= onttrytocontactme2@gmail.com> wrote:
I believe I'm running= into a bug with Flight but I'd like to confirm and get some advice on = a potential fix. I'm not sure where to look or what could be causing it= .=C2=A0

The code in question simply uploads a one-= element List<Integer> to the example server, fetches it from the serv= er, and attempts to append the data from the server to a new VectorSchemaRo= ot. It fails in the same way regardless of whether or not I construct a Vec= torSchemaRoot instance.=C2=A0

Likewise, the data f= rom the server can't be written out with the JSON writer, it'll fai= l in the same way. However, changing the data from a ListVector to an IntVe= ctor causes it to succeed.=C2=A0

Any help would be= appreciated.

Thanks,
John
Code in question:
// Set up the server and client
= BufferAllocator allocator =3D new RootAllocator(Long.MAX_VALUE);
Locatio= n l =3D Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, 12233);
Examp= leFlightServer server =3D new ExampleFlightServer(allocator, l);
server.= start();
FlightClient client =3D FlightClient.builder(allocator, l).buil= d();

// Write a one-element List<Integer>
ListVector listVe= ctor =3D ListVector.empty("list", allocator);
UnionListWriter = writer =3D listVector.getWriter();
writer.startList();
writer.integer= ().writeInt(1);
writer.endList();
writer.setValueCount(1);

// = Send that data to the server
VectorSchemaRoot root =3D VectorSchemaRoot.= of(listVector);
ClientStreamListener listener =3D client.startPut(Flight= Descriptor.path("test"), root, new AsyncPutListener());
root.s= etRowCount(1);
listener.putNext();
root.clear();
listener.complete= d();

// wait for ack to avoid memory leaks.
listener.getResult();=

// Attempt to read it back
FlightInfo info =3D client.getInfo(Fl= ightDescriptor.path("test"));
try (final FlightStream stream = =3D client.getStream(info.getEndpoints().get(0).getTicket())) {
=C2=A0 V= ectorSchemaRoot newRoot =3D stream.getRoot();
=C2=A0 while (stream.next(= )) {
=C2=A0 =C2=A0 // Copying into an entirely new VectorSchemaRoot fail= s
=C2=A0 =C2=A0 try {
=C2=A0 =C2=A0 =C2=A0 ListVector newList =3D Lis= tVector.empty("list", allocator);
=C2=A0 =C2=A0 =C2=A0 newList= .addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType()));
=C2= =A0 =C2=A0 =C2=A0 VectorSchemaRoot copyRoot =3D VectorSchemaRoot.of(newList= );
=C2=A0 =C2=A0 =C2=A0 VectorSchemaRootAppender.append(copyRoot, newRoo= t);
=C2=A0 =C2=A0 } catch (IndexOutOfBoundsException e) {
=C2=A0 =C2= =A0 =C2=A0 System.err.println("Expected IOOBE caught");
=C2=A0= =C2=A0 }

=C2=A0 =C2=A0 // The same is true if we try to copy the da= ta from the server to our VectorSchemaRoot
=C2=A0 =C2=A0 try {
=C2=A0= =C2=A0 =C2=A0 VectorSchemaRootAppender.append(root, newRoot);
=C2=A0 = =C2=A0 } catch (IndexOutOfBoundsException e) {
=C2=A0 =C2=A0 =C2=A0 Syst= em.err.println("Expected IOOBE caught again");
=C2=A0 =C2=A0 = =C2=A0 throw e;
=C2=A0 =C2=A0 }

=C2=A0 =C2=A0 root.clear();
= =C2=A0 =C2=A0 newRoot.clear();
=C2=A0 }
}
--000000000000197f7e05bb77787e--