Skip to content

Commit

Permalink
fix compat
Browse files Browse the repository at this point in the history
  • Loading branch information
niebayes committed Nov 29, 2024
1 parent b134297 commit 568c0d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/arrow_flightsql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
)

// Config struct to hold datasource configuration
// TODO(niebayes): remove the Metadata field when stable.
type config struct {
Addr string `json:"host"`
Metadata []map[string]string `json:"metadata"`
Secure bool `json:"secure"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
Token string `json:"token"`
}

Expand Down
21 changes: 19 additions & 2 deletions pkg/arrow_flightsql/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ func (d *DataSource) getTables(w http.ResponseWriter, r *http.Request) {
defer cancel()
ctx = metadata.NewOutgoingContext(ctx, d.md)

dbSchemaFilterPattern := d.getDbSchemaFilterPattern()
info, err := d.client.GetTables(ctx, &flightsql.GetTablesOpts{
TableTypes: []string{"BASE TABLE", "table"},
DbSchemaFilterPattern: &dbSchemaFilterPattern,
TableTypes: []string{"TABLE"},
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -123,7 +125,9 @@ func (d *DataSource) getColumns(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
defer cancel()
ctx = metadata.NewOutgoingContext(ctx, d.md)
dbSchemaFilterPattern := d.getDbSchemaFilterPattern()
info, err := d.client.GetTables(ctx, &flightsql.GetTablesOpts{
DbSchemaFilterPattern: &dbSchemaFilterPattern,
TableNameFilterPattern: &tableName,
IncludeSchema: true,
})
Expand Down Expand Up @@ -172,6 +176,15 @@ func (d *DataSource) getColumns(w http.ResponseWriter, r *http.Request) {
}
}

func (d *DataSource) getDbSchemaFilterPattern() string {
dbSchemaFilterPattern := "%"
value := d.md.Get("database")
if len(value) > 0 && value[0] != "" {
dbSchemaFilterPattern = value[0]
}
return dbSchemaFilterPattern
}

func newDataResponse(reader recordReader) backend.DataResponse {
var resp backend.DataResponse
frame := newFrame(reader.Schema())
Expand Down Expand Up @@ -219,7 +232,7 @@ func NewDatasource(ctx context.Context, settings backend.DataSourceInstanceSetti
}

if err := cfg.validate(); err != nil {
return nil, fmt.Errorf("FlightSQL Config Validation Error -> ", err)
return nil, fmt.Errorf("FlightSQL Config Validation Error -> %w", err)
}

client, err := newFlightSQLClient(cfg)
Expand Down Expand Up @@ -291,13 +304,17 @@ func route(ds *DataSource) backend.CallResourceHandler {
// createMetadata creates metadata from config
func createMetadata(cfg config) metadata.MD {
md := metadata.MD{}
// TODO(niebayes): skip accessing the metadata when stable.
for _, m := range cfg.Metadata {
for k, v := range m {
if _, ok := md[k]; !ok && k != "" {
md.Set(k, v)
}
}
}
if cfg.Database != "" {
md.Set("database", fmt.Sprintf(cfg.Database))
}
if cfg.Token != "" {
md.Set("Authorization", fmt.Sprintf("Bearer %s", cfg.Token))
}
Expand Down

0 comments on commit 568c0d1

Please sign in to comment.