Skip to content

Add biquery query parameter option to support parametrize query - #39389

Merged
jrmccluskey merged 3 commits into
apache:masterfrom
i05nagai:feature/go-sdk-bq
Sep 9, 2026
Merged

Add biquery query parameter option to support parametrize query#39389
jrmccluskey merged 3 commits into
apache:masterfrom
i05nagai:feature/go-sdk-bq

Conversation

@i05nagai

@i05nagai i05nagai commented Jul 20, 2026

Copy link
Copy Markdown

Addresses: #29382
Also addresses: #25096

Description

This PR supports QueryParameter for BigQueryIO in Go.
The type of bigquery.QueryParameter.Value is any so encoding/decoding should preserve the types in any.
To preserve type information, I've implemented it with encoding/gob under the following limitations:

  • user-defined struct is not supported
  • user-defined scalar type (e.g. type Counter int64)

bbigquery.QueryParameter.Value supports both types. See https://github.com/googleapis/google-cloud-go/blob/bigquery/v1.79.0/bigquery/params.go#L323.

Another possible approach is to implement a similar conversion logic to that implemented in paramValue by converting user-defined types to bigquery.QueryParameterValue explicitly.
This solution requires us to maintain the same conversion logic defined internally in the bigquery pkg. This seems over-complicated for now. But we can extend the implementation to add the conversion logic in the encodeQueryParameter function later.

Tests

I successfully ran integrated tests with

go test -v ./test/integration/io/bigqueryio \
      --runner=direct \
      --project=${PROJECT_ID} \
      --bq_dataset=${DATASET_ID}

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enables parameterized queries for BigQueryIO in the Go SDK. By allowing users to pass query parameters, it improves security and flexibility when interacting with BigQuery. The changes include the necessary infrastructure to serialize these parameters for execution within the Beam pipeline, alongside updates to integration test utilities to better support project-specific configurations.

Highlights

  • Parameterized Query Support: Added support for parameterized queries in BigQueryIO by introducing WithQueryParameters and handling the serialization of bigquery.QueryParameter objects.
  • Serialization Infrastructure: Implemented new encoding and decoding logic for query parameters using JSON to ensure compatibility with Beam's serialization requirements.
  • Integration Test Improvements: Updated integration test helpers to explicitly pass project IDs and improved table validation logic to ensure more reliable test execution.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@i05nagai i05nagai changed the title Add biquery query parameters to support parametrize query Add biquery query parameter option to support parametrize query Jul 20, 2026

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

Copy link
Copy Markdown
Contributor

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 introduces support for parameterized queries in the Go SDK's BigQuery IO connector, adding a new WithQueryParameters option, serializing parameters during pipeline execution, and updating integration tests. The reviewer feedback is highly constructive and identifies critical issues: JSON serialization will cause type loss for query parameters (e.g., converting integers to floats), which can be resolved by using gob encoding; decoding will fail on empty parameters without a guard check; tests should be expanded to cover numeric types; and encoding should be skipped when no parameters are provided to avoid overhead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sdks/go/pkg/beam/io/bigqueryio/coder.go
Comment thread sdks/go/pkg/beam/io/bigqueryio/bigquery.go
Comment thread sdks/go/pkg/beam/io/bigqueryio/coder_test.go
Comment thread sdks/go/pkg/beam/io/bigqueryio/bigquery.go
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @lostluck for label go.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

QueryParameter and QueryParameterValue contains filed with any type.
Converting go types to encoding/json lose type informations some of go
types.
The registered types are ones supported in the implementation in
paramValue method.
https://github.com/googleapis/google-cloud-go/blob/bigquery/v1.79.0/bigquery/params.go#L434
@i05nagai
i05nagai force-pushed the feature/go-sdk-bq branch from 5875abd to c4675c6 Compare July 27, 2026 12:23
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @lostluck


"TestTimers_EventTime_WithNoOutputTimestamp", // Encounter error: TimestampCombiner moved element from TIMESTAMP_MAX_VALUE to earlier time (end of global window) for window GlobalWindow
"TestTimers_ProcessingTime.*", // Flink doesn't support processing time timers.
"TestTimers_ProcessingTime.*", // Flink doesn't support processing time timers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Errant formatting change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for reviewing!
I ran go fmt against this file. The formatting matches go fmt.
As far as I can tell, go fmt runs only against sdks/go/pkg/beam in CI: https://github.com/apache/beam/blob/master/.github/workflows/go_tests.yml#L61

I can do either

  • (1) Revert this formatting
  • (2) Or create another issue and a dedicated PR to update the go fmt check to include all Go files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gofmt aligns comments vertically when part of consecutive lines in the same block, so the new formatting is correct. I wouldn't worry about trying to fix it.

@lostluck lostluck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Just one typo fix. I'd make it myself but I'm phone only at the moment.

Comment thread sdks/go/pkg/beam/io/bigqueryio/coder.go Outdated
if params == nil {
return []byte{}, nil
}
// validate each element to tell which paramaeter is unsupported.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/paramaeter/parameter/

@jrmccluskey
jrmccluskey merged commit d11883d into apache:master Sep 9, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants