Skip to content
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
20 changes: 16 additions & 4 deletions internal/commands/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,24 @@ func selectIDNamePairs(ctx context.Context, client *topline.QueryClient, sql str
rowsAny, _ := raw["rows"].([]any)
out := make([]idNamePair, 0, len(rowsAny))
for _, r := range rowsAny {
row, ok := r.([]any)
if !ok || len(row) <= idIdx || len(row) <= nameIdx {
var id, name string
switch row := r.(type) {
case map[string]any:
// Hosted warehouse returns rows as column-keyed objects, e.g.
// {"id": "...", "name": "..."}. Use column names directly.
id, _ = row["id"].(string)
name, _ = row["name"].(string)
case []any:
// Some deployments / tests return rows as positional arrays
// aligned with the `columns` order.
if len(row) <= idIdx || len(row) <= nameIdx {
continue
}
id, _ = row[idIdx].(string)
name, _ = row[nameIdx].(string)
default:
continue
}
id, _ := row[idIdx].(string)
name, _ := row[nameIdx].(string)
id = strings.TrimSpace(id)
name = strings.TrimSpace(name)
if id == "" {
Expand Down
6 changes: 5 additions & 1 deletion internal/commands/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,13 @@ func (s *pipelineLookupServer) handle(w http.ResponseWriter, r *http.Request) {
matches = append(matches, p)
}
}
// The hosted warehouse query API returns rows as column-keyed
// objects (e.g. {"id":"...","name":"..."}), not positional arrays.
// Mirror that shape here so the resolver is exercised against the
// real wire format.
rows := make([]string, 0, len(matches))
for _, p := range matches {
rows = append(rows, fmt.Sprintf(`["%s","%s"]`, p.ID, p.Name))
rows = append(rows, fmt.Sprintf(`{"id":%q,"name":%q}`, p.ID, p.Name))
}
_, _ = fmt.Fprintf(w, `{"columns":["id","name"],"rows":[%s]}`, strings.Join(rows, ","))
return
Expand Down
Loading