Skip to content

Conversation

@shollyman
Copy link
Contributor

towards internal b/447623020

@shollyman shollyman requested review from a team as code owners December 1, 2025 19:26
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the BigQuery API. label Dec 1, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @shollyman, 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 enhances the BigQuery client library by introducing support for specifying timestamp precision in table schemas. This allows users to define TIMESTAMP fields with either microsecond (default) or picosecond precision, providing finer control over data storage and retrieval for time-sensitive applications.

Highlights

  • BigQuery Schema Enhancement: Introduced a TimestampPrecision field to the FieldSchema struct, allowing users to specify the precision for TIMESTAMP type fields (microsecond or picosecond).
  • Data Conversion Logic: Implemented the necessary logic to correctly convert TimestampPrecision values between the client-side FieldSchema and the BigQuery API's TableFieldSchema.
  • Testing Coverage: Added unit and integration tests to ensure the TimestampPrecision field is correctly handled during schema conversion and table creation.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
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 adds support for timestamp precision in BigQuery schemas. The implementation is mostly correct and includes unit and integration tests. However, there is a significant issue with the current implementation that prevents setting a timestamp precision of 0, as it would be ignored and default to 6. I've suggested changing FieldSchema.TimestampPrecision to a pointer to fix this, and pointed out the necessary related changes. I've also left a couple of smaller suggestions to improve documentation clarity and the design of a new helper function.

// base 10) for seconds of TIMESTAMP type. Possible values include:
// * 6 (Default, for TIMESTAMP type with microsecond precision)
// * 12 (For TIMESTAMP type with picosecond precision)
TimestampPrecision int64
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The TimestampPrecision field should be a pointer (*int64) to correctly handle the case where a user wants to explicitly set the precision to 0.

According to BigQuery documentation, timestamp precision can be a value from 0 to 12. If not specified, it defaults to 6. With the current int64 type, it's impossible to distinguish between an unset value and an explicit 0, leading to a bug where a user-specified precision of 0 is ignored and defaults to 6.

Changing this to *int64 will allow nil to represent "not set" and a pointer to 0 to represent an explicit 0. This is a breaking change but necessary for correctness. Corresponding changes will be needed in toBQ, bqToFieldSchema, and the tests.

Suggested change
TimestampPrecision int64
TimestampPrecision *int64

Comment on lines +183 to +185
if fs.TimestampPrecision > 0 {
tfs.TimestampPrecision = &fs.TimestampPrecision
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This logic is incorrect as it prevents setting TimestampPrecision to 0. Once FieldSchema.TimestampPrecision is changed to a pointer type (*int64) as suggested in another comment, this check should be updated to test for nil instead.

Suggested change
if fs.TimestampPrecision > 0 {
tfs.TimestampPrecision = &fs.TimestampPrecision
}
if fs.TimestampPrecision != nil {
tfs.TimestampPrecision = fs.TimestampPrecision
}

Comment on lines +274 to +276
if tfs.TimestampPrecision != nil {
fs.TimestampPrecision = *tfs.TimestampPrecision
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This assignment needs to be updated to work with *int64 for FieldSchema.TimestampPrecision as suggested in another comment. Instead of dereferencing the pointer, you should assign it directly.

Suggested change
if tfs.TimestampPrecision != nil {
fs.TimestampPrecision = *tfs.TimestampPrecision
}
if tfs.TimestampPrecision != nil {
fs.TimestampPrecision = tfs.TimestampPrecision
}

Comment on lines +161 to +162
// Precision (maximum number of total digits in
// base 10) for seconds of TIMESTAMP type. Possible values include:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The description of Precision here is a bit confusing. BigQuery documentation for TIMESTAMP precision refers to the number of fractional digits for seconds. The current comment mentions "maximum number of total digits", which is how precision for NUMERIC types is usually described.

To avoid confusion, could you clarify that this is about fractional digits? For example:
// Precision is the number of fractional digits for seconds of a TIMESTAMP type.

Suggested change
// Precision (maximum number of total digits in
// base 10) for seconds of TIMESTAMP type. Possible values include:
// Precision is the number of fractional digits for seconds of a
// TIMESTAMP type. Possible values include:

Comment on lines +31 to +32
// Utility functions to deal with byproducts of wrapper types in discovery.
func int64ptr(v int64) *int64 { return &v }
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This helper function is only used in tests currently, but if FieldSchema.TimestampPrecision is changed to a pointer type as suggested in another comment, users of this library will need an exported helper to construct *int64 values.

Consider exporting this function (e.g., Int64p) and improving the comment to be more general.

Example:

// Int64p returns a pointer to an int64 value.
func Int64p(v int64) *int64 { return &v }
Suggested change
// Utility functions to deal with byproducts of wrapper types in discovery.
func int64ptr(v int64) *int64 { return &v }
// Int64p returns a pointer to an int64 value.
func Int64p(v int64) *int64 { return &v }

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.

1 participant