You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "zeroshade (via GitHub)" <gi...@apache.org> on 2023/09/15 15:19:07 UTC
[GitHub] [arrow-adbc] zeroshade commented on a diff in pull request #1071: test(python/adbc_driver_flightsql): test Flight SQL & error details
zeroshade commented on code in PR #1071:
URL: https://github.com/apache/arrow-adbc/pull/1071#discussion_r1327447423
##########
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:
can you split this onto multiple lines for readability?
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org