source-bigquery-batch: Fix behavior of DATETIME
cursors with fractional-second precision
#2086
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
BigQuery DATETIME columns only support microsecond precision, but the default serialization of the Go
civil.DateTime
struct uses nanosecond precision. Which is fine for output only, and also is fine for cursors until the capture restarts, and also is fine when the datetime values are whole seconds.But a fractional-second datetime used as a cursor will be stored as a string in the state checkpoint, and trying to feed that back to BigQuery after a restart will produce an error because there are too many digits of precision.
The fix is to handle the formatting of
civil.DateTime
values into strings ourselves and make sure it only has six digits.This change is