Skip to content

Conversation

@Linchin
Copy link
Contributor

@Linchin Linchin commented Nov 20, 2025

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquery Issues related to the googleapis/python-bigquery API. labels Nov 20, 2025
@Linchin Linchin added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Nov 24, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Nov 24, 2025
@Linchin Linchin marked this pull request as ready for review November 25, 2025 00:24
@Linchin Linchin requested review from a team as code owners November 25, 2025 00:24
@Linchin Linchin requested a review from Neenu1995 November 25, 2025 00:24
@Linchin Linchin assigned chalmerlowe and unassigned jinseopkim0 Nov 25, 2025
- 6 (Default, for TIMESTAMP type with microsecond precision)
- 12 (For TIMESTAMP type with picosecond precision)
Copy link
Contributor

Choose a reason for hiding this comment

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

should there be an enum or something for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an option, I did not choose it because the backend defined it to be an integer, and I think we can let the backend handle value validation. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

In other repos, this is something I'd define an enum for, and then accept either the enum or a raw int value

But I don't have too much context on this repo, so up to you if that makes sense here. Consistency with the rest of the code is probably more relevant


@property
def timestamp_precision(self):
"""Optional[int]: Precision (maximum number of total digits in base 10)
Copy link
Contributor

@daniel-sanche daniel-sanche Nov 25, 2025

Choose a reason for hiding this comment

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

Is this a valid docstring format? I've never return type declared at the top this way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is indeed redundant. I just went with the same format with the rest of the class properties, but looking at the doc, this format doesn't seem to be properly rendered. I will correct the format and open an issue to clean up docstrings so they follow PEP 257.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated code and opened #2340.

Possible values include:
- 6 (Default, for TIMESTAMP type with microsecond precision)
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems confusing to say 6 is the default here, since this is a getter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed to None instead, to be consistent with server behavior.

- 6 (Default, for TIMESTAMP type with microsecond precision)
- 12 (For TIMESTAMP type with picosecond precision)
Copy link
Contributor

@daniel-sanche daniel-sanche Nov 25, 2025

Choose a reason for hiding this comment

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

No mention of None?

(It says 6 is the default. Is the server enforcing that, or the client? Can this even return None?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The server does return None, if we do not set the value. This docstring is copied from the proto files. I just tried to set value to 6, and received the following error:
Invalid value for timestampPrecision: 6 is not a valid value

So here we might need to give up consistency with the proto and make sure the doc is user friendly. WDYT? I will also open a bug with the API team.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

opened internal bug 463739109 and updated docstring.

Copy link
Contributor

Choose a reason for hiding this comment

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

Usually in protos, None is equivalent to 0. So I'd recommend removing the Optional here, and have it return 0 if unset.

But yeah, we should make sure we understand the expected values here first

policy_tags = key[-2]
policy_tags_inst = None if policy_tags is None else PolicyTagList(policy_tags)
adjusted_key = key[:-1] + (policy_tags_inst,)
adjusted_key = key[:-2] + (policy_tags_inst,) + (key[-1],)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a cleaner way to do this?

Ideally self._key() could return a named tuple, so you can pull out individual entries by name

But you could also do something like:

*initial_tags, policy_tags, timestamp_precision_tag = self._key policy_tags_inst = None if policy_tags is None else PolicyTagList(policy_tags) adjusted_key = (*initial_tags, policy_tags_inst, timestamp_precision_tag) 
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is such a better idea! I have updated the code to use your version

- 6 (Default, for TIMESTAMP type with microsecond precision)
- 12 (For TIMESTAMP type with picosecond precision)
Copy link
Contributor

Choose a reason for hiding this comment

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

In other repos, this is something I'd define an enum for, and then accept either the enum or a raw int value

But I don't have too much context on this repo, so up to you if that makes sense here. Consistency with the rest of the code is probably more relevant

- 6 (Default, for TIMESTAMP type with microsecond precision)
- 12 (For TIMESTAMP type with picosecond precision)
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually in protos, None is equivalent to 0. So I'd recommend removing the Optional here, and have it return 0 if unset.

But yeah, we should make sure we understand the expected values here first


self.assertTrue(_table_exists(table))
self.assertEqual(table.table_id, table_id)
self.assertEqual(table.schema, SCHEMA_PICOSECOND)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have a test that reads back a timestamp, and makes sure its in the expected range? Or am I misunderstanding?

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 googleapis/python-bigquery API. size: m Pull request size is medium.

5 participants