Skip to content

Commit e016135

Browse files
committed
Update to work with sdk version 5 and dynamic updating of dynamic schemas. Closes #259
1 parent 5086f1b commit e016135

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

fdw.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"fmt"
1414
"io/ioutil"
1515
"log"
16+
"runtime/debug"
1617
"time"
1718
"unsafe"
1819

@@ -103,6 +104,8 @@ func goFdwGetPathKeys(state *C.FdwPlanState) *C.List {
103104
defer func() {
104105
if r := recover(); r != nil {
105106
log.Printf("[WARN] goFdwGetPathKeys failed with panic: %v", r)
107+
log.Printf("[WARN] %s", debug.Stack())
108+
106109
FdwError(fmt.Errorf("%v", r))
107110
}
108111
}()

hub/hub.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,16 @@ func (h *Hub) GetPathKeys(opts types.Options) ([]types.PathKey, error) {
407407
return nil, err
408408
}
409409

410-
connectionSchema, ok := connectionPlugin.ConnectionMap[connectionName]
410+
connectionSchema, err := connectionPlugin.GetSchema(connectionName)
411+
if err != nil {
412+
return nil, err
413+
}
414+
tableSchema, ok := connectionSchema.Schema[table]
411415
if !ok {
412-
return nil, fmt.Errorf("no schema loaded for connection '%s'", connectionName)
416+
return nil, fmt.Errorf("no schema loaded for connection '%s', table '%s'", connectionName, table)
413417
}
414-
schema := connectionSchema.Schema.Schema[table]
415-
var allColumns = make([]string, len(schema.Columns))
416-
for i, c := range schema.Columns {
418+
var allColumns = make([]string, len(tableSchema.Columns))
419+
for i, c := range tableSchema.Columns {
417420
allColumns[i] = c.Name
418421
}
419422

@@ -422,10 +425,10 @@ func (h *Hub) GetPathKeys(opts types.Options) ([]types.PathKey, error) {
422425
// build path keys based on the table key columns
423426
// NOTE: the schema data has changed in SDK version 1.3 - we must handle plugins using legacy sdk explicitly
424427
// check for legacy sdk versions
425-
if schema.ListCallKeyColumns != nil {
428+
if tableSchema.ListCallKeyColumns != nil {
426429
log.Printf("[TRACE] schema response include ListCallKeyColumns, it is using legacy protobuff interface ")
427-
pathKeys = types.LegacyKeyColumnsToPathKeys(schema.ListCallKeyColumns, schema.ListCallOptionalKeyColumns, allColumns)
428-
} else if schema.ListCallKeyColumnList != nil {
430+
pathKeys = types.LegacyKeyColumnsToPathKeys(tableSchema.ListCallKeyColumns, tableSchema.ListCallOptionalKeyColumns, allColumns)
431+
} else if tableSchema.ListCallKeyColumnList != nil {
429432
log.Printf("[TRACE] schema response include ListCallKeyColumnList, it is using the updated protobuff interface ")
430433
// generate path keys if there are required list key columns
431434
// this increases the chances that Postgres will generate a plan which provides the quals when querying the table

0 commit comments

Comments
 (0)