Skip to content

civil: unsuitable for use with BigQuery ingestion #6409

@mattmoor

Description

@mattmoor

Client

The civil.DateTime type is unsuitable for use with BigQuery DATETIME.

These types are advertised for use with BigQuery, e.g.

// This type exists to represent the TIME type in storage-based APIs like BigQuery.
// Most operations on Times are unlikely to be meaningful. Prefer the DateTime type.
type Time struct {

Environment

BigQuery data transfer service ingesting newline-delimited JSON in GCS into BigQuery.

Go Environment

Go 1.18

Code

The relevant code is where we want to use civil.DateTime for a field type so that we get the appropriate JSON encoding for BigQuery to ingest the field as DATETIME:

type Record struct {
   ...
	StartedAt          *civil.DateTime `json:"startedAt,omitempty"`
	FinishedAt         *civil.DateTime `json:"finishedAt,omitempty"`
   ...
}

Expected behavior

I would expect this type to serialize into a form compatible with DATETIME as described here, in particular:

[.F]: Up to six fractional digits (microsecond precision)

Actual behavior

Instead of microsecond precision, the types are encoded with nanosecond precision here:

return s + fmt.Sprintf(".%09d", t.Nanosecond)

This results in errors like this when BigQuery attempts to ingest these as DATETIME:

Invalid datetime string "2022-07-23T02:37:52.032499000"
Field: start_time; Value: 2022-07-23T02:37:52.032499000

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.priority: p3Desirable enhancement or fix. May not be included in next release.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions