zeroshade commented on code in PR #1597:
URL: https://github.com/apache/arrow-adbc/pull/1597#discussion_r1517886945
##########
go/adbc/driver/flightsql/flightsql_connection.go:
##########
@@ -124,16 +235,97 @@ func (c *cnxn) GetOption(key string) (string, error) {
return adbc.OptionValueEnabled, nil
}
case adbc.OptionKeyCurrentCatalog:
+ options, err := c.getSessionOptions(context.Background())
+ if err != nil {
+ return "", err
+ }
+ if catalog, ok := options["catalog"]; ok {
+ if val, ok := catalog.(string); ok {
+ return val, nil
+ }
+ return "", adbc.Error{
+ Msg: fmt.Sprintf("[FlightSQL] Server returned
non-string catalog %#v", catalog),
+ Code: adbc.StatusInternal,
+ }
+ }
return "", adbc.Error{
- Msg: "[Flight SQL] current catalog not supported",
+ Msg: "[FlightSQL] current catalog not supported",
Code: adbc.StatusNotFound,
}
case adbc.OptionKeyCurrentDbSchema:
+ options, err := c.getSessionOptions(context.Background())
+ if err != nil {
+ return "", err
+ }
+ if schema, ok := options["schema"]; ok {
+ if val, ok := schema.(string); ok {
+ return val, nil
+ }
+ return "", adbc.Error{
+ Msg: fmt.Sprintf("[FlightSQL] Server returned
non-string schema %#v", schema),
+ Code: adbc.StatusInternal,
+ }
+ }
return "", adbc.Error{
- Msg: "[Flight SQL] current schema not supported",
+ Msg: "[FlightSQL] current schema not supported",
Code: adbc.StatusNotFound,
}
+ case OptionSessionOptions:
+ options, err := c.getSessionOptions(context.Background())
+ if err != nil {
+ return "", err
+ }
+ encoded, err := json.Marshal(options)
+ if err != nil {
+ return "", adbc.Error{
+ Msg: fmt.Sprintf("[Flight SQL] Could not
encode option values: %s", err.Error()),
+ Code: adbc.StatusInternal,
+ }
+ }
+ return string(encoded), nil
+ }
+ if strings.HasPrefix(key, OptionSessionOptionPrefix) {
+ options, err := c.getSessionOptions(context.Background())
+ if err != nil {
+ return "", err
+ }
+ name := key[len(OptionSessionOptionPrefix):]
+ return getSessionOption(options, name, "", "a string")
+ }
+ if strings.HasPrefix(key, OptionBoolSessionOptionPrefix) {
+ options, err := c.getSessionOptions(context.Background())
+ if err != nil {
+ return "", err
+ }
+ name := key[len(OptionBoolSessionOptionPrefix):]
+ v, err := getSessionOption(options, name, false, "a boolean")
+ if err != nil {
+ return "", err
+ }
+ if v {
+ return adbc.OptionValueEnabled, nil
+ }
+ return adbc.OptionValueDisabled, nil
+ }
+ if strings.HasPrefix(key, OptionStringListSessionOptionPrefix) {
Review Comment:
Can we make this a little bit cleaner and use another switch here?
```go
switch {
case strings.HasPrefix(key, OptionSessionOptionPrefix):
...
case strings.HasPrefix(key, OptionBoolSessionOptionPrefix):
...
```
--
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]