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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/spf13/pflag v1.0.9
github.com/spf13/viper v1.10.1
github.com/stackql-labs/omnisdk v0.1.1-alpha06
github.com/stackql/any-sdk v0.5.4-alpha01
github.com/stackql/any-sdk v0.5.5-alpha01
github.com/stackql/go-suffix-map v0.0.1-alpha01
github.com/stackql/psql-wire v0.1.2-beta01
github.com/stackql/stackql-parser v0.0.16-alpha02
Expand Down Expand Up @@ -151,7 +151,7 @@ require (
golang.org/x/tools v0.44.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/grpc v1.83.0 // indirect
google.golang.org/grpc v1.83.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ github.com/spiffe/go-spiffe/v2 v2.7.0 h1:uXe1MflJoHw58wAUvxVlcM7WpKtijWG7I1UidcG
github.com/spiffe/go-spiffe/v2 v2.7.0/go.mod h1:47Q0Q9/AqGha8QLHp+kxpH4Wca7X7EnOtlIJy3mxZ3U=
github.com/stackql-labs/omnisdk v0.1.1-alpha06 h1:jVetiuZa6J1uWJ4vPc/YQtol4l7Lgoq281UWvYXw6GM=
github.com/stackql-labs/omnisdk v0.1.1-alpha06/go.mod h1:WzvNj/bVv53yGFsVJpYWCJC1xAEdmQSFJl9eVpkRpCY=
github.com/stackql/any-sdk v0.5.4-alpha01 h1:AyjD2Hyk7D8v1fHHtLpfeqQRxKuj7rC71dzi1Zh9LoA=
github.com/stackql/any-sdk v0.5.4-alpha01/go.mod h1:BiE8uiAJMUa8n4U/yMlhvrVhE2M+5Rt8utBXYkwj9To=
github.com/stackql/any-sdk v0.5.5-alpha01 h1:Omj/EuF0hx8oai54aRZMrWkjsV11YK532lq4Spfvjiw=
github.com/stackql/any-sdk v0.5.5-alpha01/go.mod h1:DV6KrDVMIpbuWHm4YAdMtCsszbpdzLL0JUXpEX3wDMU=
github.com/stackql/go-suffix-map v0.0.1-alpha01 h1:TDUDS8bySu41Oo9p0eniUeCm43mnRM6zFEd6j6VUaz8=
github.com/stackql/go-suffix-map v0.0.1-alpha01/go.mod h1:QAi+SKukOyf4dBtWy8UMy+hsXXV+yyEE4vmBkji2V7g=
github.com/stackql/psql-wire v0.1.2-beta01 h1:+0xeLLam3nbI1iv84pWJYGYw5VO5S/+eICRbdu6+dj8=
Expand Down Expand Up @@ -518,8 +518,8 @@ gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.83.0 h1:JeNZEKJFbQxArAMl+hiytHauacDNqJUllNfmIMmpqnQ=
google.golang.org/grpc v1.83.0/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ=
google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y=
google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 4 additions & 0 deletions internal/stackql/astvisit/query_rewriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ func (v *standardQueryRewriteAstVisitor) Visit(node sqlparser.SQLNode) error {
_, isBareCol := node.Expr.(*sqlparser.ColName)
if isBareCol {
ss, _ = schema.GetProperty(col.Name)
if ss != nil {
// A wire-spelled projection selects the display column (any-sdk #131).
col = col.WithDisplayName(schema.Tabulate(false, ""))
}
}
cd := formulation.NewColumnDescriptor(col.Alias, col.Name, col.Qualifier, col.DecoratedColumn, node, ss, col.Val)
v.columnDescriptors = append(v.columnDescriptors, cd)
Expand Down
9 changes: 9 additions & 0 deletions internal/stackql/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,15 @@ func transformOpenapiStackqlAuthToLocal(authDTO formulation.AuthDTO) *dto.AuthCt
AuthStyle: authDTO.GetAuthStyle(),
AccountID: authDTO.GetAccountID(),
AccoountIDEnvVar: authDTO.GetAccountIDEnvVar(),
// Doc-level OCI env var indirections (issue #710); a runtime --auth context
// still wins via updateAuthContextIfNotExists.
OciTenancyOCIDEnvVar: authDTO.GetOciTenancyOCIDEnvVar(),
OciUserOCIDEnvVar: authDTO.GetOciUserOCIDEnvVar(),
OciFingerprintEnvVar: authDTO.GetOciFingerprintEnvVar(),
OciPrivateKeyEnvVar: authDTO.GetOciPrivateKeyEnvVar(),
OciPrivateKeyFilePathEnvVar: authDTO.GetOciPrivateKeyPathEnvVar(),
OciPassphraseEnvVar: authDTO.GetOciPassphraseEnvVar(),
OciRegionEnvVar: authDTO.GetOciRegionEnvVar(),
}
successor, successorExists := authDTO.GetSuccessor()
currentParent := rv
Expand Down
21 changes: 21 additions & 0 deletions internal/stackql/parserutil/column_handle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parserutil

import (
"github.com/stackql/any-sdk/public/formulation"
"github.com/stackql/stackql-parser/go/vt/sqlparser"
)

Expand All @@ -15,3 +16,23 @@ type ColumnHandle struct {
Type sqlparser.ValType
Val *sqlparser.SQLVal
}

// WithDisplayName re-keys a wire-spelled column reference to the tabulation
// display name the backend column carries (snake_case_aliases, any-sdk #131),
// keeping the original spelling as the output alias. No-op when the names agree.
func (ch ColumnHandle) WithDisplayName(tabulation formulation.Tabulation) ColumnHandle {
if tabulation == nil || !ch.IsColumn {
return ch
}
for _, tc := range tabulation.GetColumns() {
if tc.GetWireName() == ch.Name && tc.GetName() != ch.Name {
if ch.Alias == "" {
ch.Alias = ch.Name
}
ch.Name = tc.GetName()
ch.DecoratedColumn = ""
return ch
}
}
return ch
}
27 changes: 23 additions & 4 deletions internal/stackql/primitivegenerator/statement_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package primitivegenerator
import (
"encoding/json"
"fmt"
"math"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -516,9 +517,18 @@ func (pb *standardPrimitiveGenerator) analyzeWhere(
return &sqlparser.Where{Type: where.Type, Expr: retVal}, paramsSupplied, nil
}

func extractVarDefFromExec(node *sqlparser.Exec, argName string) (*sqlparser.ExecVarDef, error) {
func extractVarDefFromExec(
node *sqlparser.Exec,
method formulation.OperationStore,
argName string,
) (*sqlparser.ExecVarDef, error) {
for _, varDef := range node.ExecVarDefs {
if varDef.ColIdent.GetRawVal() == argName {
rawName := varDef.ColIdent.GetRawVal()
if rawName == argName {
return &varDef, nil
}
// A snake alias resolves to its wire parameter (any-sdk #131).
if p, ok := method.GetParameter(rawName); ok && p.GetName() == argName {
return &varDef, nil
}
}
Expand Down Expand Up @@ -594,7 +604,7 @@ func (pb *standardPrimitiveGenerator) AnalyzeUnaryExec(
}
for k, param := range requiredParams {
logging.GetLogger().Debugln(fmt.Sprintf("param = %v", param))
_, err = extractVarDefFromExec(node, k)
_, err = extractVarDefFromExec(node, method, k)
if err != nil {
return nil, fmt.Errorf("required param not supplied for exec: %w", err)
}
Expand Down Expand Up @@ -813,13 +823,22 @@ func (pb *standardPrimitiveGenerator) parseExecPayload(
), nil
}

// acceptsJSONNumber: JSON numbers unmarshal as float64, so an integral value
// also satisfies an integer property (issue #725).
func acceptsJSONNumber(ss formulation.Schema, val float64) bool {
return ss.IsFloat() || (ss.IsIntegral() && val == math.Trunc(val))
}

//nolint:funlen,unparam,gocognit // TODO: refactor
func (pb *standardPrimitiveGenerator) analyzeSchemaVsMap(
handlerCtx handler.HandlerContext,
schema formulation.Schema,
payload map[string]interface{},
method formulation.OperationStore,
) error {
if schema == nil {
return fmt.Errorf("method '%s' has no request body schema", method.GetName())
}
requiredElements := make(map[string]bool)
schemas, err := schema.GetProperties()
if err != nil {
Expand Down Expand Up @@ -887,7 +906,7 @@ func (pb *standardPrimitiveGenerator) analyzeSchemaVsMap(
}
return fmt.Errorf("key '%s' expected to contain element of type 'bool' but instead it is type '%T'", k, val)
case float64:
if ss.IsFloat() {
if acceptsJSONNumber(ss, val) {
delete(requiredElements, k)
continue
}
Expand Down
4 changes: 4 additions & 0 deletions internal/stackql/primitivegenerator/unary_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (pb *standardPrimitiveGenerator) assembleUnarySelectionBuilder(
col.Name)
}
}
if foundSchema != nil {
// A wire-spelled projection selects the display column (any-sdk #131).
col = col.WithDisplayName(insertTabulation)
}
selectTabulation.PushBackColumn(
formulation.NewColumnDescriptor(
col.Alias,
Expand Down
115 changes: 112 additions & 3 deletions test/python/stackql_test_tooling/flask/native_test/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ def _oci_auth_fields(req) -> dict:
# assert on; the signature itself varies per request (date) so it is not echoed.
auth = req.headers.get("Authorization", "")
fields = dict(re.findall(r'(\w+)="([^"]*)"', auth))
# The raw request line target is what (request-target) signs; RAW_URI keeps
# any dangling '?' that Flask's full_path would mask.
raw_uri = req.environ.get("RAW_URI") or req.environ.get("REQUEST_URI") or req.path
return {
"auth_scheme": auth.split(" ")[0] if auth else "",
"auth_version": fields.get("version", ""),
"auth_algorithm": fields.get("algorithm", ""),
"auth_key_id": fields.get("keyId", ""),
"auth_signed_headers": fields.get("headers", ""),
"auth_request_target": f"{req.method.lower()} {raw_uri}",
}


def _raw_query() -> str:
# The query string exactly as sent (still percent-encoded).
return request.query_string.decode("utf-8")


def create_app() -> Flask:
app = Flask(__name__)

Expand All @@ -61,6 +70,54 @@ def casing_echo_post():
}
)

@app.get("/casing/echo_header")
def casing_echo_header_get():
# Kebab-case wire header; the SQL side addresses it as openai_organization.
return jsonify(
{
"echoed_org": request.headers.get("openai-organization"),
"echoed_query": _raw_query(),
}
)

@app.get("/casing/echo_bodyless/<binary_id>")
def casing_echo_bodyless_get(binary_id):
return jsonify(
{
"BinaryId": binary_id,
"VpcId": request.args.get("VpcId"),
"echoed_query": _raw_query(),
}
)

@app.post("/casing/activate/<id>")
def casing_activate_post(id):
# Response deliberately omits the id (stackql #705 / #726 shape).
return jsonify({"status": "ACTIVE", "requestId": "req-activate-1"})

# ---- request body coercion (any-sdk #129 / stackql #725) ---------------

def _coerce_echo(service_id):
return jsonify(
{
"serviceId": service_id,
"echoed_body": request.get_data(as_text=True),
"ok": True,
}
)

@app.post("/coerce/echo")
def coerce_echo_post():
return _coerce_echo("")

@app.patch("/coerce/echo/<service_id>")
def coerce_echo_patch(service_id):
return _coerce_echo(service_id)

@app.put("/coerce/echo/<service_id>")
def coerce_echo_put(service_id):
return _coerce_echo(service_id)

@app.get("/casing/echo_strict")
def casing_echo_strict_get():
# Same echo semantics as /casing/echo; the spec-side difference is that
Expand Down Expand Up @@ -110,9 +167,9 @@ def odata_people():
# which OData options stackql pushed down via any-sdk ApplyPushdown.
echoed = " ".join(f"{k}={v}" for k, v in request.args.items())
people = [
{"name": "Alice", "city": "NYC", "age": 30, "echoed": echoed},
{"name": "Acme", "city": "SF", "age": 40, "echoed": echoed},
{"name": "Bob", "city": "LA", "age": 25, "echoed": echoed},
{"name": "Alice", "city": "NYC", "age": 30, "created_at": "2024-03-01", "echoed": echoed},
{"name": "Acme", "city": "SF", "age": 40, "created_at": "2024-01-15", "echoed": echoed},
{"name": "Bob", "city": "LA", "age": 25, "created_at": "2024-02-10", "echoed": echoed},
]
# Honour $top server-side so a wrongly-pushed $top is observable as an
# under-count (the grain-change guard test relies on this).
Expand Down Expand Up @@ -202,6 +259,58 @@ def paged_items_unterminated():
rows = [dict(item, wire_page=page) for item in window]
return jsonify({"items": rows, "result_info": {"page": page}})

# ---- Link-header pagination (any-sdk #123) ------------------------------

_linked_pages = {
"": (1, ["DB1", "DB2"], "DB3"),
"DB3": (2, ["DB3", "DB4"], "DB5"),
"DB5": (3, ["DB5", "DB6"], None),
}

def _linked_page(header_name, rel="next"):
# Three pages of two, keyed by fromName; pages 1-2 carry a next link
# built from the host the client actually used (docker vs native).
page, names, next_name = _linked_pages.get(request.args.get("fromName", ""), (0, [], None))
rows = [{"name": n, "wire_page": page, "wire_query": _raw_query()} for n in names]
resp = jsonify({"items": rows})
if next_name is not None:
resp.headers[header_name] = f'<{request.host_url.rstrip("/")}{request.path}?fromName={next_name}>; rel="{rel}"'
return resp

@app.get("/linked/items")
def linked_items():
return _linked_page("Link")

@app.get("/linked/items_xnext")
def linked_items_xnext():
return _linked_page("X-Next-Page")

@app.get("/linked/items_prev_only")
def linked_items_prev_only():
return _linked_page("Link", rel="prev")

# ---- cursor pagination, requestToken.encoding (any-sdk #121) ------------

_cursor_pages = {
"": (["C1", "C2"], "page_AAAA=="),
"page_AAAA==": (["C3", "C4"], "page_BBBB=="),
"page_BBBB==": (["C5", "C6"], None),
}

@app.get("/cursor/items")
def cursor_items():
# A percent-escaped cursor is rejected the way strict cursor parsers do.
raw = _raw_query()
raw_page = re.search(r"(?:^|&)page=([^&]*)", raw)
if raw_page and "%" in raw_page.group(1):
return jsonify({"error": {"message": "The page token is invalid: percent-escaped cursor"}}), 400
names, next_page = _cursor_pages.get(request.args.get("page", ""), ([], None))
rows = [{"name": n, "wire_query": raw} for n in names]
body = {"items": rows}
if next_page is not None:
body["next_page"] = next_page
return jsonify(body)

# ---- GraphQL pluggable cursor strategies (issue 684) --------------------

@app.post("/graphql/keyset")
Expand Down
2 changes: 1 addition & 1 deletion test/python/stackql_test_tooling/registry_rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def rewrite_provider(args :ProviderArgs):
for srv in path_item_servers:
srv['url'] = _replace_server_url(srv['url'], args.replacement_host, args.port)
path_item_servers
for k in ('get', 'put', 'post', 'delete', 'head'):
for k in ('get', 'put', 'post', 'patch', 'delete', 'head'):
operation = path_item.get(k)
if operation:
operation_servers = operation.get('servers', [])
Expand Down
27 changes: 27 additions & 0 deletions test/registry/src/stackql_native_test/v0.1.0/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,32 @@ providerServices:
$ref: stackql_native_test/v0.1.0/services/paged.yaml
title: REST page_number pagination
version: v0.1.0
linked:
description: Link-header (RFC 5988) pagination.
id: linked:v0.1.0
name: linked
preferred: true
service:
$ref: stackql_native_test/v0.1.0/services/linked.yaml
title: Link-header pagination
version: v0.1.0
cursor:
description: Cursor pagination requestToken encoding.
id: cursor:v0.1.0
name: cursor
preferred: true
service:
$ref: stackql_native_test/v0.1.0/services/cursor.yaml
title: Cursor pagination request token encoding
version: v0.1.0
coerce:
description: Schema-driven request body coercion.
id: coerce:v0.1.0
name: coerce
preferred: true
service:
$ref: stackql_native_test/v0.1.0/services/coerce.yaml
title: Request body coercion
version: v0.1.0
servers: []
version: v0.1.0
Loading
Loading