zeroshade commented on code in PR #1071:
URL: https://github.com/apache/arrow-adbc/pull/1071#discussion_r1327449302
##########
go/adbc/driver/flightsql/cmd/testserver/main.go:
##########
@@ -39,23 +39,49 @@ import (
"github.com/apache/arrow/go/v13/arrow/memory"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
+ "google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/types/known/anypb"
+ "google.golang.org/protobuf/types/known/wrapperspb"
)
type ExampleServer struct {
flightsql.BaseServer
}
+func StatusWithDetail(code codes.Code, message string, details
...proto.Message) error {
+ p := status.New(code, message).Proto()
+ // Have to do this by hand because gRPC uses deprecated proto import
+ for _, detail := range details {
+ any, err := anypb.New(detail)
+ if err != nil {
+ panic(err)
+ }
+ p.Details = append(p.Details, any)
+ }
+ return status.FromProto(p).Err()
+}
+
func (srv *ExampleServer) ClosePreparedStatement(ctx context.Context, request
flightsql.ActionClosePreparedStatementRequest) error {
return nil
}
func (srv *ExampleServer) CreatePreparedStatement(ctx context.Context, req
flightsql.ActionCreatePreparedStatementRequest) (result
flightsql.ActionCreatePreparedStatementResult, err error) {
+ if req.GetQuery() == "error_create_prepared_statement" {
+ err = status.Error(codes.InvalidArgument, "expected error
(DoAction)")
+ return
+ }
+ if req.GetQuery() == "error_create_prepared_statement_detail" {
+ detail1 := wrapperspb.String("detail1")
+ detail2 := wrapperspb.String("detail2")
+ err = StatusWithDetail(codes.InvalidArgument, "expected error
(DoAction)", detail1, detail2)
+ return
+ }
result.Handle = []byte(req.GetQuery())
return
}
func (srv *ExampleServer) GetFlightInfoPreparedStatement(_ context.Context,
cmd flightsql.PreparedStatementQuery, desc *flight.FlightDescriptor)
(*flight.FlightInfo, error) {
- if bytes.Equal(cmd.GetPreparedStatementHandle(),
[]byte("error_do_get")) || bytes.Equal(cmd.GetPreparedStatementHandle(),
[]byte("error_do_get_stream")) {
+ if bytes.Equal(cmd.GetPreparedStatementHandle(),
[]byte("error_do_get")) || bytes.Equal(cmd.GetPreparedStatementHandle(),
[]byte("error_do_get_stream")) || bytes.Equal(cmd.GetPreparedStatementHandle(),
[]byte("error_do_get_detail")) || bytes.Equal(cmd.GetPreparedStatementHandle(),
[]byte("error_do_get_stream_detail")) ||
bytes.Equal(cmd.GetPreparedStatementHandle(), []byte("forever")) {
Review Comment:
Alternately you could just do
```go
switch string(cmd.GetPreparedStatementHandle()) {
...
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]