googleapis / googleapis/google-cloud-go
google-cloud-go/blob/main/bigquery/storage/managedwriter/adapt: adapt package not working for BigQuery DATETIME type
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
## Client
BigQuery managedwriter (cloud.google.com/go/bigquery/storage/managedwriter/adapt)
## Environment
Alpine Docker on GKE
go version go1.23.0 linux/amd64
## Code and Dependencies
```go
package main
import (
"time"
"strconv"
bq "cloud.google.com/go/bigquery/storage/managedwriter"
)
func main() {
req := map[string]interface{}{
"entry_time": strconv.FormatInt(time.Now().UTC().UnixMicro(), 10),
}
var result *managedwriter.AppendResult
// sends using adapt-generated schema with DATETIME field
}
```
go.mod
```text
module example
go 1.23.0
require (
cloud.google.com/go/bigquery v1.61.0
)
```
## Expected behavior
It should write to BigQuery table
## Actual behavior
If i use time.Now().Format("2006-01-02 15:04:05.000000"), then i get error at "err = protojson.Unmarshal(eventInBytes, msg)" as it needs int with error "proto: (line 1:15): invalid value for int64 field entryTime: \"2025-07-24 15:27:29.663095\"", but if i use strconv.FormatInt(time.Now().UnixMicro(), 10), then i get error at "res, err := result.FullResponse(ctx)" with error as "Cannot return an invalid datetime value of 1753350970678947 microseconds expressed as civil time, according to civil_time encoding. The range of valid datetime values is [0001-01-01 00:00:00, 9999-12-31 23:59:59.999999] on field entry_time."
In BigQuery field type is DATETIME, and in my code corresponding variable's field type is String
Is there any other way i'm supposed to send it?
Contributor guide
Assessment
This issue has not been assessed yet.