Skip to content

fix(bigquery): allow timestamp format overrides in createQueryStream#7905

Closed
rafal-hawrylak wants to merge 1 commit intogoogleapis:mainfrom
rafal-hawrylak:bigquery-timestamp-format-param-pass-fix
Closed

fix(bigquery): allow timestamp format overrides in createQueryStream#7905
rafal-hawrylak wants to merge 1 commit intogoogleapis:mainfrom
rafal-hawrylak:bigquery-timestamp-format-param-pass-fix

Conversation

@rafal-hawrylak
Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug in createQueryStream where formatOptions were being stripped from the query object before reaching the internal request builder. This caused the library to always use the default ISO8601_STRING format, which is rejected by some BigQuery backends.

By extracting these options in queryAsStream_ and passing them through to the request builder, users can now successfully opt-out of the new default behavior when necessary.

Impact

  • createQueryStream now correctly handles formatOptions.timestampOutputFormat and formatOptions.useInt64Timestamp if provided in the options object.
  • Bypasses 'timestamp_output_format is not supported yet' errors in restricted environments.

Testing

  • Updated unit tests in test/bigquery.ts to verify the 'Gatekeeper' fix.
  • Added a specific test case to verify that formatOptions are correctly passed through.
  • Verified that all existing BigQuery tests pass.

## Description

This PR fixes a bug in createQueryStream where formatOptions were being
stripped from the query object before reaching the internal request builder.
This caused the library to always use the default ISO8601_STRING format,
which is rejected by some BigQuery backends.

By extracting these options in queryAsStream_ and passing them through to
the request builder, users can now successfully opt-out of the new default
behavior when necessary.

## Impact

- createQueryStream now correctly handles formatOptions.timestampOutputFormat
  and formatOptions.useInt64Timestamp if provided in the options object.
- Bypasses 'timestamp_output_format is not supported yet' errors in restricted
  environments.

## Testing

- Updated unit tests in test/bigquery.ts to verify the 'Gatekeeper' fix.
- Added a specific test case to verify that formatOptions are correctly passed through.
- Verified that all existing BigQuery tests pass.
@rafal-hawrylak rafal-hawrylak requested a review from a team as a code owner March 27, 2026 10:32
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the BigQuery API. label Mar 27, 2026
Copy link
Copy Markdown
Contributor

@danieljbruce danieljbruce left a comment

Choose a reason for hiding this comment

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

The required change isn't this simple. This removes a desired feature for some of our users. I can take this on if you like.

delete query.wrapIntegers;
delete query.parseJSON;
delete (query as any)['formatOptions.timestampOutputFormat'];
delete (query as any)['formatOptions.useInt64Timestamp'];
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.

We can't just delete timestampOutputFormat and useInt64Timestamp properties from being sent to the backend. Some of our users are likely relying on this feature.

The core issue is that this code was developed on the old repository with a project that had allowlisted a feature that we don't plan to make GA until Q3. So we has to pin the version as shown in #7286. We have a few options:

  1. Make source code changes so that requests don't set timestampOutputFormat by default and then this won't be an issue for users. The tests still won't pass for a project that isn't allowlisted, but it won't affect users.

  2. We can stage a PR to reverse the changes between 8.1.1 and 8.2.0 so that you can add newer changes and do a release which will unblock future work. Then we can revert this PR which will introduce the changes again when the feature is GA.

Option #2 is probably cleaner. Let me know what you think.

Copy link
Copy Markdown
Contributor Author

@rafal-hawrylak rafal-hawrylak Mar 31, 2026

Choose a reason for hiding this comment

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

We can't just delete timestampOutputFormat and useInt64Timestamp properties from being sent to the backend. Some of our users are likely relying on this feature.

Both timestampOutputFormat and useInt64Timestamp are copied to ops and sent to backend via ops, just as other options like location or parseJSON. As far as I understand it's just the query struct itself is stripped from those additional options.

Option #2 is probably cleaner. Let me know what you think.

We do not rely on or expect time formatting changes so for us the most important factor is whichever is the fastest to be released.

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.

Both timestampOutputFormat and useInt64Timestamp are copied to ops and sent to backend via ops

I see. But if a user calls the query method directly and we release the latest version of Bigquery then we are going to see #7286 come back again. I am working on this on main...revert-bq-changes. I'll try to get a fix out today

Copy link
Copy Markdown
Contributor

@danieljbruce danieljbruce left a comment

Choose a reason for hiding this comment

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

The main issue remains that if we bump the release to the latest version then users will still encounter the issue that they encountered earlier. I'll try to fix this.

delete query.wrapIntegers;
delete query.parseJSON;
delete (query as any)['formatOptions.timestampOutputFormat'];
delete (query as any)['formatOptions.useInt64Timestamp'];
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.

Both timestampOutputFormat and useInt64Timestamp are copied to ops and sent to backend via ops

I see. But if a user calls the query method directly and we release the latest version of Bigquery then we are going to see #7286 come back again. I am working on this on main...revert-bq-changes. I'll try to get a fix out today

@danieljbruce
Copy link
Copy Markdown
Contributor

I actually also see failures when I run the system tests for a non-allowlisted timestamp precision project. How did the system tests perform for your project?

image

@danieljbruce
Copy link
Copy Markdown
Contributor

#7946 was merged so I think we can close this as it is obselete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants