diff --git a/clients/bigquery/storagewrite.go b/clients/bigquery/storagewrite.go index d6933eb98..44a72e3f3 100644 --- a/clients/bigquery/storagewrite.go +++ b/clients/bigquery/storagewrite.go @@ -46,6 +46,8 @@ func columnToTableFieldSchema(column columns.Column) (*storagepb.TableFieldSchem fieldType = storagepb.TableFieldSchema_DATE case ext.TimestampTZKindType: fieldType = storagepb.TableFieldSchema_TIMESTAMP + case ext.TimestampNTZKindType: + fieldType = storagepb.TableFieldSchema_DATETIME default: return nil, fmt.Errorf("unsupported extended time details type: %q", column.KindDetails.ExtendedTimeDetails.Type) } @@ -89,15 +91,45 @@ func columnsToMessageDescriptor(cols []columns.Column) (*protoreflect.MessageDes return &messageDescriptor, nil } +const ( + microLength = 20 + secondShift = 0 + minuteShift = 6 + hourShift = 12 + dayShift = 17 + monthShift = 22 + yearShift = 26 +) + // This is a reimplementation of https://github.com/googleapis/java-bigquerystorage/blob/f79acb5cfdd12253bca1c41551c478400120d2f9/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/CivilTimeEncoder.java#L143 // See https://cloud.google.com/java/docs/reference/google-cloud-bigquerystorage/latest/com.google.cloud.bigquery.storage.v1.CivilTimeEncoder // And https://cloud.google.com/pubsub/docs/bigquery#date_time_int func encodePacked64TimeMicros(value time.Time) int64 { - var result = int64(value.Nanosecond() / 1000) - result |= int64(value.Second()) << 20 - result |= int64(value.Minute()) << 26 - result |= int64(value.Hour()) << 32 - return result + return int64(encodePacked32TimeSeconds(value))<