GoogleCloudPlatform / GoogleCloudPlatform/cloud-spanner-emulator

Timestamps reported in change records values are incorrect

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

Description

We're using change streams to observe changes to a table, which has two `TIMESTAMP` columns: `resource_version` and `previous_resource_version`.

`resource_version` is always updated with `PENDING_COMMIT_TIMESTAMP()` (which has [microseconds precision](https://cloud.google.com/spanner/docs/commit-timestamp#:~:text=Spanner%20commit%20timestamps%20have%20microsecond%20granularity%2Cand%20they%20are%20converted%20to%20nanoseconds%20when%20stored%20in%20TIMESTAMP%20columns.)), while `previous_resource_version` is updated with computed value.

After modifying the entry we can see following values in the table:

```
+--------------+----------------------------+-----------------------------+
| value | resource_version | previous_resource_version |
+--------------+----------------------------+-----------------------------+
| bmV3LXZhbHVl | 2025-02-19T13:55:36.43168Z | 2025-02-19T13:55:36.429694Z |
+--------------+----------------------------+-----------------------------+
```

However change record with this modification contains following "NEW" values:

```json
{
"previous_resource_version": "2025-02-19T13:55:36Z",
"resource_version": "9999-12-31T23:59:59Z",
"value": "bmV3LXZhbHVl"
}
```

There are two problems with this change record modification:
* `resource_version` column seem to contain placeholder value, instead of final value of `PENDING_COMMIT_TIMESTAMP()`.
* Both `resource_version` and `previous_resource_version` are reported with seconds precision, [instead of nanoseconds](https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#timestamp_type).

When running the same code against cloud Spanner instance, we're seeing correct values in the change record (i.e. final value of commit timestamp and timestamps with microseconds).

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.