-
Notifications
You must be signed in to change notification settings - Fork 88
Closed
Labels
api: bigquerystorageIssues related to the googleapis/java-bigquerystorage API.Issues related to the googleapis/java-bigquerystorage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Environment details
- BigQuery storage API
- OS type and version: MacOS
- Java version: 17
- version(s): 2.11.1, in gradle
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.11.1'
Steps to reproduce
- Have a table with a TIMESTAMP column
- Use JsonStreamWriter to set this column to a string-encoded timestamp, such as
java.sql.Timestamp.from(java.time.Instant.now()).toString() - Write data to BigQuery, commit the stream
- 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
Assignees
Labels
api: bigquerystorageIssues related to the googleapis/java-bigquerystorage API.Issues related to the googleapis/java-bigquerystorage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.