Skip to content
Closed
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/spf13/viper v1.10.1
github.com/stackql-labs/omnisdk v0.1.6-alpha05
github.com/stackql-labs/omnisdk v0.1.6-alpha19
github.com/stackql/any-sdk v0.6.1-beta01
github.com/stackql/go-suffix-map v0.0.1-alpha02
github.com/stackql/psql-wire v0.1.2-beta02
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
github.com/spiffe/go-spiffe/v2 v2.7.0 h1:uXe1MflJoHw58wAUvxVlcM7WpKtijWG7I1UidcGh6g4=
github.com/spiffe/go-spiffe/v2 v2.7.0/go.mod h1:47Q0Q9/AqGha8QLHp+kxpH4Wca7X7EnOtlIJy3mxZ3U=
github.com/stackql-labs/omnisdk v0.1.6-alpha05 h1:o4dcS21CFLRvBH4cNtTWyVroTrRELz/42/tgKGrIs4E=
github.com/stackql-labs/omnisdk v0.1.6-alpha05/go.mod h1:bMRymDVvjy9j7v7nm01LugE5mF2I85ClmsjiUzURZ+I=
github.com/stackql-labs/omnisdk v0.1.6-alpha19 h1:3ksjQhgtsmI1h4LKFoGBjAcEPGNvOY2id3ugpiYKryk=
github.com/stackql-labs/omnisdk v0.1.6-alpha19/go.mod h1:bMRymDVvjy9j7v7nm01LugE5mF2I85ClmsjiUzURZ+I=
github.com/stackql/any-sdk v0.6.1-beta01 h1:2Jqru76BDS87Jd95n5P56ruUoB0NWQZEbVQIXa3wlOs=
github.com/stackql/any-sdk v0.6.1-beta01/go.mod h1:xUR2t/dy8d01Ut4n3WdMe1lfxG5ipq/VNwa9dXDXI/o=
github.com/stackql/go-suffix-map v0.0.1-alpha02 h1:JI4aiq/OfHW4a/BiNqK31NbyaR94zlUOhGZof3G/OUo=
Expand Down
5 changes: 5 additions & 0 deletions internal/stackql/datasource/sql_datasource/generic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sql_datasource //nolint:revive,stylecheck // package name is helpful

import (
"context"
"database/sql"
"fmt"

Expand Down Expand Up @@ -86,3 +87,7 @@ func (ds *genericSQLDataSource) GetTableMetadata(args ...string) (sqltable.SQLTa
// `
// return nil, fmt.Errorf("could not obtain sql data source table metadata for table = '%s'", tableName)
// }

func (ds *genericSQLDataSource) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) {
return ds.db.QueryContext(ctx, query, args...)
}
7 changes: 7 additions & 0 deletions internal/stackql/datasource/sql_datasource/sql_datasource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sql_datasource //nolint:stylecheck,revive // package name is helpful

import (
"context"
"database/sql"
"fmt"

Expand All @@ -9,6 +10,12 @@ import (
"github.com/stackql/stackql/internal/stackql/datasource/sqltable"
)

// ContextQuerier is the optional cancellation-capable query handle used by read adapters.
// Existing SQLDataSource implementations remain source compatible.
type ContextQuerier interface {
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
}

type SQLDataSource interface {
Begin() (*sql.Tx, error)
Exec(string, ...interface{}) (sql.Result, error)
Expand Down
2 changes: 1 addition & 1 deletion internal/stackql/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (hc *standardHandlerContext) GetSupportedProviders(extended bool) (map[stri
}
// Every locally available bundle is also addressable document-first,
// once that has been opted into.
if intrinsic.IsUnstableEnabled() {
if intrinsic.IsExtendedCatalogEnabled() {
unstable := intrinsic.UnstablePrefix + pn
retVal[unstable] = map[string]interface{}{
"name": unstable,
Expand Down
74 changes: 74 additions & 0 deletions internal/stackql/intrinsic/completion_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package intrinsic

import (
"maps"
"slices"

"github.com/stackql-labs/omnisdk/pkg/omnisdk"
"github.com/stackql-labs/omnisdk/pkg/query"
)

type completionSchemaTable struct {
omnisdk.Table
columns []string
types map[string]omnisdk.ColumnType
}

func withCompletionSchema(target, resource omnisdk.Table) omnisdk.Table {
columns := map[string]bool{}
types := map[string]omnisdk.ColumnType{}
for _, method := range resource.Methods() {
for _, name := range method.Columns() {
columns[name] = true
}
maps.Copy(types, method.ColumnTypes())
}
return &completionSchemaTable{Table: target, columns: slices.Sorted(maps.Keys(columns)), types: types}
}
func (t *completionSchemaTable) Methods() []omnisdk.MethodSignature {
methods := t.Table.Methods()
out := make([]omnisdk.MethodSignature, len(methods))
for i, method := range methods {
out[i] = newCompletedMethod(method, t.columns, t.types)
}
return out
}

type completedMethod struct {
omnisdk.MethodSignature
columns []string
types map[string]omnisdk.ColumnType
}

func newCompletedMethod(
base omnisdk.MethodSignature, columns []string, types map[string]omnisdk.ColumnType,
) omnisdk.MethodSignature {
return &completedMethod{MethodSignature: base, columns: slices.Clone(columns), types: maps.Clone(types)}
}
func (m *completedMethod) Columns() []string { return slices.Clone(m.columns) }
func (m *completedMethod) ColumnTypes() map[string]omnisdk.ColumnType { return maps.Clone(m.types) }
func (m *completedMethod) ServerEnvironmentBindings() map[string]string {
if metadata, ok := m.MethodSignature.(omnisdk.ServerEnvironmentBindings); ok {
return metadata.ServerEnvironmentBindings()
}
return nil
}

func describeMutationTable(registry string, target query.Target, await bool) (omnisdk.Table, error) {
table, err := omnisdk.DescribeMutation(registry, target.Resource().Handle(), target.Verb().String())
if err != nil || !await {
return table, err
}
resource, err := omnisdk.DescribeTable(registry, target.Resource().Handle())
if err != nil {
return nil, err
}
return withCompletionSchema(table, resource), nil
}

func (m *completedMethod) ServerTransportDefaults() map[string]string {
if metadata, ok := m.MethodSignature.(omnisdk.ServerTransportDefaults); ok {
return metadata.ServerTransportDefaults()
}
return nil
}
Loading
Loading