Skip to content

JsonToProtoMessage issue with TIMESTAMP fields - milliseconds vs microseconds #1604

@daniels-cysiv

Description

@daniels-cysiv

Environment details

  1. BigQuery storage API
  2. OS type and version: MacOS
  3. Java version: 17
  4. version(s): 2.11.1, in gradle implementation 'com.google.cloud:google-cloud-bigquerystorage:2.11.1'

Steps to reproduce

  1. Have a table with a TIMESTAMP column
  2. Use JsonStreamWriter to set this column to a string-encoded timestamp, such as java.sql.Timestamp.from(java.time.Instant.now()).toString()
  3. Write data to BigQuery, commit the stream
  4. Time shows up in BigQuery as early 1970, not 2022

Code example

Problem is in com.google.cloud.bigquery.storage.v1.JsonToProtoMessage around line 307:

          } else if (fieldSchema.getType() == TableFieldSchema.Type.TIMESTAMP) {
            if (val instanceof String) {
              protoMsg.setField(fieldDescriptor, Timestamp.valueOf((String) val).getTime());

The issue is that this sets the time as milliseconds from epoch, while BigQuery expects microseconds from epoch.

There's a workaround, convert the time to micro-from-epoch in my code and set the field as a Long instead of a String, but the code in JsonToProtoMessage as it stands is incorrect.

Metadata

Metadata

Labels

api: bigquerystorageIssues related to the googleapis/java-bigquerystorage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions