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

Open Beginner friendly
#347 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
cpp
Domain
databases

Research direction

Start in backend/actions/change_stream.cc at CloudValueToJSONValue and inspect the TYPE_TIMESTAMP formatting path described in the issue. Reproduce the change-stream keys case and verify that the resulting JSON preserves fractional timestamp precision while existing behavior remains correct.

Written by the indexing model from the issue text.

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 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.

Dominant language
C++
Stars
334
Forks
77
Avg merge
8m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GoogleCloudPlatform/cloud-spanner-emulator

All issues in GoogleCloudPlatform/cloud-spanner-emulator

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.