Repository navigation
Pass the declared type of ARRAY and STRUCT query parameters - #525
Open
kfirco-torq wants to merge 2 commits into
Open
kfirco-torq wants to merge 2 commits into
kfirco-torq wants to merge 2 commits into
Conversation
Points github.com/goccy/googlesqlite at the unreleased change that adds googlesqlite.TypedValue. Replace this commit with a version bump once that change is released.
An ARRAY or STRUCT query parameter decodes to Go slices and maps, from
which googlesqlite has to infer its type. That loses what only the
request's parameterType carries: struct field order (structValues is a
JSON object), the type of a NULL field, the element type of an empty
array, and the type of scalar leaves, which the REST API sends as
strings. The query saw the wrong type: a STRUCT as STRING ("Cannot
access field id on a value with type STRING"), fields in random order,
INT64 fields as strings.
Convert the parameterType into a googlesqlite.Type and pass the value as
a googlesqlite.TypedValue, which googlesqlite casts and declares with
that type.
A NULL scalar nested inside an ARRAY or STRUCT decoded as "", because
QueryParameterValue.Value is a plain string and a top-level parameter's
nil-pointer treatment does not apply to StructValues, which holds
values. applyNullQueryParameters now walks the raw JSON of ARRAY and
STRUCT parameters and marks every nested scalar whose value is JSON
null or absent with NullFields: ["Value"], bigqueryv2's own way of
saying a field is NULL, and queryParameterValueToGoValue reads it as
nil.
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on goccy/googlesqlite#106, which adds
googlesqlite.TypedValue. The first commit is a temporaryreplacethat pointsgo.modat that change so CI can build. Once googlesqlite releases it, I'll swap that commit for a version bump.Problem
ARRAY and STRUCT query parameters decode to Go slices and maps, and googlesqlite then has to infer their type. That loses information that only the request's
parameterTypecarries:structValuesis a JSON object);A nested NULL also decoded as
"".QueryParameterValue.Valueis a plain string, and the nil-pointer handling used for top-level NULLs can't reach intoStructValues, which holds values rather than pointers.Minimal repro (
jobs.query):{"query": "SELECT TO_JSON_STRING(@p)", "useLegacySql": false, "parameterMode": "NAMED", "queryParameters": [{"name": "p", "parameterType": {"type": "ARRAY", "arrayType": {"type": "STRUCT", "structTypes": [ {"name": "id", "type": {"type": "INT64"}}, {"name": "name", "type": {"type": "STRING"}}]}}, "parameterValue": {"arrayValues": [{"structValues": {"name": {"value": null}, "id": {"value": "2"}}}]}}]}[{"id":2,"name":null}]main:"[{\"name\":\"\",\"id\":\"2\"}]". The value is a STRING, the fields are in random order,idis a string andnameis"".@p.idfails to analyze withCannot access field id on a value with type STRING. The Go client shows the same behaviour.Fix
repository.Queryconverts theparameterTypeof an ARRAY or STRUCT parameter into agooglesqlite.Typeand passes the value as agooglesqlite.TypedValue. googlesqlite then casts the value to that type and declares the parameter with it.applyNullQueryParameterswalks the raw JSON of ARRAY and STRUCT parameters. It marks every nested scalar whosevalueis JSON null or absent withNullFields: ["Value"], which is bigqueryv2's own way of saying a field is NULL, so no sentinel string is needed.queryParameterValueToGoValuereads a marked value as nil.Tests
TestArrayAndStructQueryParameterTypes(server/server_test.go) covers:ARRAY<STRUCT<id INT64, name STRING, tags ARRAY<STRING>>>sent over REST, with unordered fields, a NULL field and an empty array;All three subtests fail on
mainand pass with this change.go test ./...passes, includingtest/e2e.Notes
ARRAY<DATE>element, which overlaps with Coerce every scalar parameter leaf, not just the top-level parameter #516. The two changes don't conflict.