joellubi commented on code in PR #38385: URL: https://github.com/apache/arrow/pull/38385#discussion_r1528232635
########## go/arrow/flight/flightsql/client.go: ########## @@ -218,6 +218,58 @@ func (c *Client) ExecuteSubstraitUpdate(ctx context.Context, plan SubstraitPlan, return updateResult.GetRecordCount(), nil } +var ErrTooManyPutResults = fmt.Errorf("%w: server sent multiple PutResults, expected one ", arrow.ErrInvalid) + +// ExecuteIngest is for executing a bulk ingestion and only returns the number of affected rows. +func (c *Client) ExecuteIngest(ctx context.Context, rdr array.RecordReader, reqOptions *ExecuteIngestOpts, opts ...grpc.CallOption) (n int64, err error) { + var ( + desc *flight.FlightDescriptor + stream pb.FlightService_DoPutClient + wr *flight.Writer + res *pb.PutResult + updateResult pb.DoPutUpdateResult + ) + + cmd := (*pb.CommandStatementIngest)(reqOptions) + if desc, err = descForCommand(cmd); err != nil { + return + } + + if stream, err = c.Client.DoPut(ctx, opts...); err != nil { + return + } + + wr = flight.NewRecordWriter(stream, ipc.WithAllocator(c.Alloc), ipc.WithSchema(rdr.Schema())) + defer wr.Close() + + wr.SetFlightDescriptor(desc) + + for rdr.Next() { + rec := rdr.Record() + wr.Write(rec) + } + Review Comment: I updated this to handle the error cases you described. I looked at a few places in the code where a function consumes a RecordReader to see the `Release` semantics they use. The pattern I generally saw was that the callee retains the reader while using it and then releases it when finished, but it is still the caller's responsibility to release the original reference to the reader. I went with those same semantics here and updated the godoc comment to indicate that. I enabled allocation checking in the tests to ensure these kinds of things get caught going forward. I also added some client-side validation of the request pb for fields that are not considered optional in the proto spec. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org