GoogleCloudPlatform / GoogleCloudPlatform/cloud-spanner-emulator

Change-stream mods.keys JSON drops sub-second precision for TIMESTAMP columns

Open
#347 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
334
Forks
77
Avg merge
8m
Merged PRs (30d)
2

Description

When a tracked table has a `TIMESTAMP` column in its primary key, the change-stream `DataChangeRecord.mods[].keys` JSON encodes that column without fractional seconds. Real Spanner preserves up to 9 fractional digits.

Repro:
1. CREATE TABLE t (commit_ts TIMESTAMP NOT NULL, k INT64) PRIMARY KEY (commit_ts, k) + CREATE CHANGE STREAM s FOR t
2. Insert a row with commit_ts = TIMESTAMP '1970-01-21T14:09:51.234567890Z'
3. Read the change-stream; mods[0].keys.commit_ts is "1970-01-21T14:09:51Z" (decimals dropped)

Cause: [backend/actions/change_stream.cc CloudValueToJSONValue](https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/blob/29ac12f2bb17cead8ca06a5db6b1bb4e5bf0d8d3/backend/actions/change_stream.cc#L565) uses `absl::FormatTime("%Y-%m-%d%ET%H:%M:%SZ", ...)` for `TYPE_TIMESTAMP` — `%S` emits integer seconds. Real Spanner emits fractional. The fix is `%E*S` (or `%E9S`).

Same function as #328 (UUID encoding), similar shape of fix.

Affected: any consumer that reconstructs row identity from keys JSON when a TIMESTAMP is part of the PK.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.