Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonToProtoMessage issue with TIMESTAMP fields - milliseconds vs microseconds #1604

Closed
daniels-cysiv opened this issue Apr 1, 2022 · 2 comments
Assignees
Labels
api: bigquerystorage Issues related to the googleapis/java-bigquerystorage API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@daniels-cysiv
Copy link

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.

@product-auto-label product-auto-label bot added the api: bigquerystorage Issues related to the googleapis/java-bigquerystorage API. label Apr 1, 2022
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Apr 2, 2022
@dark0dave
Copy link
Contributor

dark0dave commented Apr 2, 2022

Hey, this should be fixed by: #1589, when 2.12.0 comes out.

@stephaniewang526 stephaniewang526 self-assigned this Apr 4, 2022
@stephaniewang526 stephaniewang526 added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. labels Apr 4, 2022
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Apr 4, 2022
@stephaniewang526
Copy link
Contributor

Please upgrade the client lib version to v2.12.0 (https://github.com/googleapis/java-bigquerystorage/releases/tag/v2.12.0) which fixed this issue. Thanks!

@stephaniewang526 stephaniewang526 removed the triage me I really want to be triaged. label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquerystorage Issues related to the googleapis/java-bigquerystorage API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants