Skip to content

Commit 4a1229c

Browse files
authored
GH-33867: [Go][FlightSQL] Allow passing grpc call options to PreparedStatement methods (#33868)
### Rationale for this change To allow propagating timeouts among other call options when using PreparedStatements with FlightSQL we need to update the function signatures to allow passing the call options to them. ### Are there any user-facing changes? The signatures for the methods on PreparedStatement objects have been updated to accept `opts... grpc.CallOption` as their last parameter. This shouldn't break any existing usage of the methods (since they are optional) but would cause a problem if consumers set up interfaces based on them. * Closes: #33867 Authored-by: Matt Topol <[email protected]> Signed-off-by: Matt Topol <[email protected]>
1 parent 247c2e6 commit 4a1229c

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

‎go/arrow/flight/flightsql/client.go‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ func (c *Client) Prepare(ctx context.Context, mem memory.Allocator, query string
355355

356356
prep = &PreparedStatement{
357357
client: c,
358-
opts: opts,
359358
handle: result.PreparedStatementHandle,
360359
datasetSchema: dsSchema,
361360
paramSchema: paramSchema,
@@ -383,7 +382,6 @@ func (c *Client) Close() error { return c.Client.Close() }
383382
// should be called when no longer needed.
384383
type PreparedStatement struct {
385384
client *Client
386-
opts []grpc.CallOption
387385
handle []byte
388386
datasetSchema *arrow.Schema
389387
paramSchema *arrow.Schema
@@ -397,7 +395,7 @@ type PreparedStatement struct {
397395
// then the parameter bindings will be sent before execution.
398396
//
399397
// Will error if already closed.
400-
func (p *PreparedStatement) Execute(ctx context.Context) (*flight.FlightInfo, error) {
398+
func (p *PreparedStatement) Execute(ctx context.Context, opts ...grpc.CallOption) (*flight.FlightInfo, error) {
401399
if p.closed {
402400
return nil, errors.New("arrow/flightsql: prepared statement already closed")
403401
}
@@ -410,7 +408,7 @@ func (p *PreparedStatement) Execute(ctx context.Context) (*flight.FlightInfo, er
410408
}
411409

412410
if p.hasBindParameters() {
413-
pstream, err := p.client.Client.DoPut(ctx, p.opts...)
411+
pstream, err := p.client.Client.DoPut(ctx, opts...)
414412
if err != nil {
415413
return nil, err
416414
}
@@ -430,13 +428,13 @@ func (p *PreparedStatement) Execute(ctx context.Context) (*flight.FlightInfo, er
430428
}
431429
}
432430

433-
return p.client.getFlightInfo(ctx, desc, p.opts...)
431+
return p.client.getFlightInfo(ctx, desc, opts...)
434432
}
435433

436434
// ExecuteUpdate executes the prepared statement update query on the server
437435
// and returns the number of rows affected. If SetParameters was called,
438436
// the parameter bindings will be sent with the request to execute.
439-
func (p *PreparedStatement) ExecuteUpdate(ctx context.Context) (nrecords int64, err error) {
437+
func (p *PreparedStatement) ExecuteUpdate(ctx context.Context, opts ...grpc.CallOption) (nrecords int64, err error) {
440438
if p.closed {
441439
return 0, errors.New("arrow/flightsql: prepared statement already closed")
442440
}
@@ -455,7 +453,7 @@ func (p *PreparedStatement) ExecuteUpdate(ctx context.Context) (nrecords int64,
455453
return
456454
}
457455

458-
if pstream, err = p.client.Client.DoPut(ctx, p.opts...); err != nil {
456+
if pstream, err = p.client.Client.DoPut(ctx, opts...); err != nil {
459457
return
460458
}
461459
if p.hasBindParameters() {
@@ -529,7 +527,7 @@ func (p *PreparedStatement) ParameterSchema() *arrow.Schema { return p.paramSche
529527
// statement from the server. It should otherwise be identical to DatasetSchema.
530528
//
531529
// Will error if already closed.
532-
func (p *PreparedStatement) GetSchema(ctx context.Context) (*flight.SchemaResult, error) {
530+
func (p *PreparedStatement) GetSchema(ctx context.Context, opts ...grpc.CallOption) (*flight.SchemaResult, error) {
533531
if p.closed {
534532
return nil, errors.New("arrow/flightsql: prepared statement already closed")
535533
}
@@ -541,7 +539,7 @@ func (p *PreparedStatement) GetSchema(ctx context.Context) (*flight.SchemaResult
541539
return nil, err
542540
}
543541

544-
return p.client.getSchema(ctx, desc, p.opts...)
542+
return p.client.getSchema(ctx, desc, opts...)
545543
}
546544

547545
func (p *PreparedStatement) clearParameters() {
@@ -585,7 +583,7 @@ func (p *PreparedStatement) SetRecordReader(binding array.RecordReader) {
585583
// Close calls release on any parameter binding record and sends
586584
// a ClosePreparedStatement action to the server. After calling
587585
// Close, the PreparedStatement should not be used again.
588-
func (p *PreparedStatement) Close(ctx context.Context) error {
586+
func (p *PreparedStatement) Close(ctx context.Context, opts ...grpc.CallOption) error {
589587
if p.closed {
590588
return errors.New("arrow/flightsql: already closed")
591589
}
@@ -609,7 +607,7 @@ func (p *PreparedStatement) Close(ctx context.Context) error {
609607
}
610608

611609
action := &flight.Action{Type: actionType, Body: body}
612-
_, err = p.client.Client.DoAction(ctx, action, p.opts...)
610+
_, err = p.client.Client.DoAction(ctx, action, opts...)
613611
if err != nil {
614612
return err
615613
}

‎go/arrow/flight/flightsql/client_test.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func getAction(cmd proto.Message) *flight.Action {
132132
func (s *FlightSqlClientSuite) SetupTest() {
133133
s.mockClient = FlightServiceClientMock{}
134134
s.sqlClient.Client = &s.mockClient
135+
s.callOpts = []grpc.CallOption{grpc.EmptyCallOption{}}
135136
}
136137

137138
func (s *FlightSqlClientSuite) TearDownTest() {
@@ -358,9 +359,9 @@ func (s *FlightSqlClientSuite) TestPreparedStatementExecute() {
358359

359360
prepared, err := s.sqlClient.Prepare(context.TODO(), memory.DefaultAllocator, query, s.callOpts...)
360361
s.NoError(err)
361-
defer prepared.Close(context.TODO())
362+
defer prepared.Close(context.TODO(), s.callOpts...)
362363

363-
info, err := prepared.Execute(context.TODO())
364+
info, err := prepared.Execute(context.TODO(), s.callOpts...)
364365
s.NoError(err)
365366
s.Equal(&emptyFlightInfo, info)
366367
}
@@ -411,15 +412,15 @@ func (s *FlightSqlClientSuite) TestPreparedStatementExecuteParamBinding() {
411412

412413
prepared, err := s.sqlClient.Prepare(context.TODO(), memory.DefaultAllocator, query, s.callOpts...)
413414
s.NoError(err)
414-
defer prepared.Close(context.TODO())
415+
defer prepared.Close(context.TODO(), s.callOpts...)
415416

416417
paramSchema := prepared.ParameterSchema()
417418
rec, _, err := array.RecordFromJSON(memory.DefaultAllocator, paramSchema, strings.NewReader(`[{"id": 1}]`))
418419
s.NoError(err)
419420
defer rec.Release()
420421

421422
prepared.SetParameters(rec)
422-
info, err := prepared.Execute(context.TODO())
423+
info, err := prepared.Execute(context.TODO(), s.callOpts...)
423424
s.NoError(err)
424425
s.Equal(&emptyFlightInfo, info)
425426
}
@@ -475,7 +476,7 @@ func (s *FlightSqlClientSuite) TestPreparedStatementExecuteReaderBinding() {
475476

476477
prepared, err := s.sqlClient.Prepare(context.TODO(), memory.DefaultAllocator, query, s.callOpts...)
477478
s.NoError(err)
478-
defer prepared.Close(context.TODO())
479+
defer prepared.Close(context.TODO(), s.callOpts...)
479480

480481
paramSchema := prepared.ParameterSchema()
481482
rec, _, err := array.RecordFromJSON(memory.DefaultAllocator, paramSchema, strings.NewReader(`[{"id": 1}]`))
@@ -486,7 +487,7 @@ func (s *FlightSqlClientSuite) TestPreparedStatementExecuteReaderBinding() {
486487
s.NoError(err)
487488
prepared.SetRecordReader(rdr)
488489

489-
info, err := prepared.Execute(context.TODO())
490+
info, err := prepared.Execute(context.TODO(), s.callOpts...)
490491
s.NoError(err)
491492
s.Equal(&emptyFlightInfo, info)
492493
}

0 commit comments

Comments
 (0)