Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit d18a043

Browse files
committed
address comments
1 parent 73156f7 commit d18a043

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

google/cloud/bigquery/_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,15 @@ def bytes_to_py(self, value, field):
254254
if _not_null(value, field):
255255
return base64.standard_b64decode(_to_bytes(value))
256256

257-
def timestamp_to_py(self, value, field):
257+
def timestamp_to_py(self, value, field) -> datetime.datetime | str | None:
258258
"""Coerce 'value' to a datetime, if set or not nullable. If timestamp
259259
is of picosecond precision, preserve the string format."""
260260
if field.timestamp_precision == enums.TimestampPrecision.PICOSECOND:
261261
return value
262262
if _not_null(value, field):
263263
# value will be a integer in seconds, to microsecond precision, in UTC.
264264
return _datetime_from_microseconds(int(value))
265+
return None
265266

266267
def datetime_to_py(self, value, field):
267268
"""Coerce 'value' to a datetime, if set or not nullable.

google/cloud/bigquery/_job_helpers.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,15 @@ def _to_query_request(
287287
# Default to standard SQL.
288288
request_body.setdefault("useLegacySql", False)
289289

290-
# Since jobs.query can return results, ensure we use the lossless timestamp
291-
# format. See: https://github.com/googleapis/python-bigquery/issues/395
292290
request_body.setdefault("formatOptions", {})
293-
request_body["formatOptions"]["useInt64Timestamp"] = True # type: ignore
294291

292+
# Cannot specify both use_int64_timestamp and timestamp_output_format.
295293
if timestamp_precision == enums.TimestampPrecision.PICOSECOND:
296-
# Cannot specify both use_int64_timestamp and timestamp_output_format.
297-
del request_body["formatOptions"]["useInt64Timestamp"]
298-
299294
request_body["formatOptions"]["timestampOutputFormat"] = "ISO8601_STRING"
295+
else:
296+
# Since jobs.query can return results, ensure we use the lossless
297+
# timestamp format. See: https://github.com/googleapis/python-bigquery/issues/395
298+
request_body["formatOptions"]["useInt64Timestamp"] = True
300299

301300
if timeout is not None:
302301
# Subtract a buffer for context switching, network latency, etc.

google/cloud/bigquery/client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,7 +3552,7 @@ def query(
35523552

35533553
if (
35543554
timestamp_precision == enums.TimestampPrecision.PICOSECOND
3555-
and api_method == enums.QueryApiMethod.INSERT
3555+
and api_method != enums.QueryApiMethod.QUERY
35563556
):
35573557
raise ValueError(
35583558
"Picosecond Timestamp is only supported when `api_method "
@@ -4167,13 +4167,11 @@ def list_rows(
41674167
if start_index is not None:
41684168
params["startIndex"] = start_index
41694169

4170-
params["formatOptions.useInt64Timestamp"] = True
4171-
4170+
# Cannot specify both use_int64_timestamp and timestamp_output_format.
41724171
if timestamp_precision == enums.TimestampPrecision.PICOSECOND:
4173-
# Cannot specify both use_int64_timestamp and timestamp_output_format.
4174-
del params["formatOptions.useInt64Timestamp"]
4175-
41764172
params["formatOptions.timestampOutputFormat"] = "ISO8601_STRING"
4173+
else:
4174+
params["formatOptions.useInt64Timestamp"] = True
41774175

41784176
row_iterator = RowIterator(
41794177
client=self,

0 commit comments

Comments
 (0)