{"record":{"id":"ef96e2e69ea89487","repo":"apache/beam","slug":"bigqueryio-query-failed-to-encode-query-parameters","errorCode":null,"errorMessage":"bigqueryio.Query: failed to encode query parameters","messagePattern":"bigqueryio\\.Query: failed to encode query parameters","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/bigqueryio/bigquery.go","lineNumber":161,"sourceCode":"func Query(s beam.Scope, project, q string, t reflect.Type, options ...func(*QueryOptions) error) beam.PCollection {\n\ts = s.Scope(\"bigquery.Query\")\n\treturn query(s, project, q, t, options...)\n}\n\nfunc query(s beam.Scope, project, query string, t reflect.Type, options ...func(*QueryOptions) error) beam.PCollection {\n\tmustInferSchema(t)\n\n\tqueryOptions := QueryOptions{}\n\tfor _, opt := range options {\n\t\tif err := opt(&queryOptions); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n\n\timp := beam.Impulse(s)\n\tqueryParameters, err := encodeQueryParameters(queryOptions.parameters)\n\tif err != nil {\n\t\tpanic(errors.Wrapf(err, \"bigqueryio.Query: failed to encode query parameters\"))\n\t}\n\treturn beam.ParDo(\n\t\ts,\n\t\t&queryFn{Project: project, Query: query, Type: beam.EncodedType{T: t}, QueryParameters: queryParameters, Options: queryOptions},\n\t\timp,\n\t\tbeam.TypeDefinition{Var: beam.XType, T: t},\n\t)\n}\n\ntype queryFn struct {\n\t// Project is the project.\n\tProject string `json:\"project\"`\n\t// Query is the query statement.\n\tQuery string `json:\"query\"`\n\t// Type is the encoded schema type.\n\tType beam.EncodedType `json:\"type\"`\n\t// QueryParameters are serialized query parameters for parameterized queries.\n\tQueryParameters []byte `json:\"query_parameters\"`","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/bigqueryio/bigquery.go#L143-L179","documentation":"In query (sdks/go/pkg/beam/io/bigqueryio/bigquery.go), the user-supplied query parameters are serialized on the driver side via encodeQueryParameters before being embedded in the ParDo; failure is wrapped as \"bigqueryio.Query: failed to encode query parameters\" and panics. It means a query parameter value has a type or value BigQuery IO cannot serialize.","triggerScenarios":"Calling beamio.Query with queryOptions.parameters containing a value of an unsupported Go type (e.g. an arbitrary struct, map, or nil value) in the query parameter list.","commonSituations":"Passing Go-native types not in the supported parameter set (string, int/float, bool, time.Time, []byte, slices of scalars) as QueryParameter values.","solutions":["Restrict query parameters to supported scalar/slice types (string, numeric, bool, time.Time, []byte).","Inspect the wrapped err to identify the offending parameter and convert it to a supported type.","For complex values, serialize them yourself (e.g. JSON into a string parameter) and parse inside the query.","Use beam.TryQuery-style construction if available, or recover the panic in a wrapper to fail gracefully at pipeline build time."],"exampleFix":"// before\nparams := []bigqueryio.QueryParameter{{Name: \"f\", Value: myStruct{}}}\nbeamio.Query(s, proj, sql, t, params...)\n// after\nparams := []bigqueryio.QueryParameter{{Name: \"f\", Value: myStruct.ID}} // supported scalar\nbeamio.Query(s, proj, sql, t, params...)","handlingStrategy":"validation","validationCode":"func validateQueryParams(ps []bigqueryio.QueryParameter) error {\n    for _, p := range ps {\n        switch p.Value.(type) {\n        case nil, string, int, int64, float64, bool, time.Time, []byte:\n        default:\n            return fmt.Errorf(\"unsupported query parameter type %T for %q\", p.Value, p.Name)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"func safeQuery(...) (beam.PCollection, error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"query setup failed: %v\", r)\n        }\n    }()\n    return beamio.Query(s, proj, sql, t, params...), nil\n}","preventionTips":["Only pass scalar and scalar-slice query parameter values","Serialize complex values to strings yourself before querying","Validate parameter types at pipeline construction time"],"tags":["bigquery","query-parameters","encoding","beam-io"],"backgroundTag":"json-marshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}