Skip to content

fix(tool/bigquery): handle omitted optional parameters with typed NULLs#3051

Open
Deeven-Seru wants to merge 2 commits intogoogleapis:mainfrom
Deeven-Seru:fix-3033-bq-optional-parameters
Open

fix(tool/bigquery): handle omitted optional parameters with typed NULLs#3051
Deeven-Seru wants to merge 2 commits intogoogleapis:mainfrom
Deeven-Seru:fix-3033-bq-optional-parameters

Conversation

@Deeven-Seru
Copy link
Copy Markdown
Contributor

Description

This PR fixes a runtime bigquery: nil parameter error that occurred when optional parameters were omitted in BigQuery tool calls. The issue was caused by the tool sending untyped nil values to the BigQuery API, which the SDK does not accept for parameters.

Impact:

  • Resolves crashes when executing queries with omitted optional parameters.
  • Enables the use of IS NULL logic and optional filters in BigQuery SQL statements.

Summary of Solution:

  • Typed NULL Mapping: Refactored parameter processing to map tool-level nil values to specific BigQuery SDK types (NullString, NullInt64, NullFloat64, NullBool).
  • REST API Support: Implemented NullFields handling for the low-level REST client to ensure NULL values are correctly marshaled during dry runs.
  • Array Support: Added handling for typed nil slices for array parameters to ensure alignment with standard SQL expectations.
  • Verification: Added comprehensive unit tests in bigquerysql_invoke_test.go to validate mapping for all supported scalar and collection types.

PR Checklist

  • Make sure you reviewed CONTRIBUTING.md
  • Make sure to open an issue as a bug/issue before writing your code!
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #3033

@Deeven-Seru Deeven-Seru requested review from a team as code owners April 14, 2026 07:27
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the BigQuery SQL tool to better handle optional parameters and NULL values by introducing a dedicated buildQueryParameters function. It also adds comprehensive unit tests for parameter building. The review feedback correctly identifies a potential issue with named parameter detection using simple string containment, which could lead to false positives, and suggests handling the TypeMap parameter type to prevent potential nil pointer issues.

Comment thread internal/tools/bigquery/bigquerysql/bigquerysql.go Outdated
Comment thread internal/tools/bigquery/bigquerysql/bigquerysql.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error processing GCP request: unable to execute query: bigquery: nil parameter

2 participants