Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deserializeDeparsedSortGroup #449

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions fdw.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ func init() {

//export goLog
func goLog(msg *C.char) {
log.Println("[WARN] " + C.GoString(msg))
log.Println("[INFO] " + C.GoString(msg))
}

// Given a list of FdwDeparsedSortGroup and a FdwPlanState,
// construct a list FdwDeparsedSortGroup that can be pushed down
//
//export goFdwCanSort
func goFdwCanSort(deparsed *C.List, planstate *C.FdwPlanState) *C.List {
log.Println("[WARN] goFdwCanSort deparsed", deparsed)
// This will be the list of FdwDeparsedSortGroup items that can be pushed down
var pushDownList *C.List = nil

Expand Down Expand Up @@ -111,7 +110,8 @@ func goFdwCanSort(deparsed *C.List, planstate *C.FdwPlanState) *C.List {
// add deparsedSortGroup to pushDownList
pushDownList = C.lappend(pushDownList, unsafe.Pointer(deparsedSortGroup))
} else {
log.Printf("[INFO] goFdwCanSort column %s CANNOT be pushed down", columnName)
log.Printf("[INFO] goFdwCanSort column %s CANNOT be pushed down - not pushing down any further columns", columnName)
break
}
}

Expand All @@ -121,6 +121,9 @@ func goFdwCanSort(deparsed *C.List, planstate *C.FdwPlanState) *C.List {
func getSortableFields(foreigntableid C.Oid) map[string]proto.SortOrder {
opts := GetFTableOptions(types.Oid(foreigntableid))
connection := GetSchemaNameFromForeignTableId(types.Oid(foreigntableid))
if connection == constants.InternalSchema || connection == constants.LegacyCommandSchema {
return nil
}

tableName := opts["table"]
pluginHub := hub.GetHub()
Expand Down Expand Up @@ -305,6 +308,8 @@ func goFdwBeginForeignScan(node *C.ForeignScanState, eflags C.int) {
// if we are NOT explaining, create an iterator to scan for us
if !explain {
var sortOrder = getSortColumns(execState)
log.Printf("[INFO] goFdwBeginForeignScan, table '%s', sortOrder: %v", opts["table"], sortOrder)

ts := int64(C.GetSQLCurrentTimestamp(0))
iter, err := pluginHub.GetIterator(columns, quals, unhandledRestrictions, int64(execState.limit), sortOrder, ts, opts)
if err != nil {
Expand Down
40 changes: 22 additions & 18 deletions fdw/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,29 +680,33 @@ deserializeDeparsedSortGroup(List *items)
FdwDeparsedSortGroup *key =
palloc0(sizeof(FdwDeparsedSortGroup));

lc = list_head(lfirst(k));
key->attname = (Name)strdup(strVal(lfirst(lc)));

lc = lnext(items, lc);
key->attnum = (int)intVal(lfirst(lc));
List *list = lfirst(k);

lc = lnext(items, lc);
key->reversed = (bool)intVal(lfirst(lc));
lc = list_head(lfirst(k));
key->attname = (Name) strdup(strVal(lfirst(lc)));

lc = lnext(items, lc);
key->nulls_first = (bool)intVal(lfirst(lc));
lc = lnext(list, lc);
key->attnum = (int) intVal(lfirst(lc));

lc = lnext(items, lc);
if (lfirst(lc) != NULL)
key->collate = (Name)strdup(strVal(lfirst(lc)));
else
key->collate = NULL;
lc = lnext(list, lc);
key->reversed = (bool) intVal(lfirst(lc));

lc = lnext(items, lc);
key->key = (PathKey *)lfirst(lc);
lc = lnext(list, lc);
key->nulls_first = (bool) intVal(lfirst(lc));

result = lappend(result, key);
}
lc = lnext(list, lc);
if(lfirst(lc) != NULL)
key->collate = (Name) strdup(strVal(lfirst(lc)));
else
key->collate = NULL;

lc = lnext(list, lc);
key->key = (PathKey *) lfirst(lc);

result = lappend(result, key);
}

return result;

return result;
}
2 changes: 1 addition & 1 deletion hub/connection_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (f *connectionFactory) createConnectionPlugin(pluginFQN string, connectionN
// load the config for this connection
connection, ok := steampipeconfig.GlobalConfig.Connections[connectionName]
if !ok {
log.Printf("[INFO] connectionFactory.createConnectionPlugin create connection %s - no config found so reloading config", connectionName)
log.Printf("[INFO] connectionFactory.createConnectionPlugin create connection %s - no config found so reloading config!", connectionName)

// ask hub to reload config - it's possible we are being asked to import a newly added connection
// TODO remove need for hub to load config at all
Expand Down
Loading