Skip to content

fix(spanner): compare FLOAT32, INTERVAL, UUID - #16728

Open
colinmoy wants to merge 2 commits into
googleapis:mainfrom
colinmoy:fix-spanner-value-equality
Open

colinmoy wants to merge 2 commits into
googleapis:mainfrom
colinmoy:fix-spanner-value-equality

Conversation

@colinmoy

@colinmoy colinmoy commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

google::cloud::spanner::Value::operator== previously returned true for any two non-NULL values of type FLOAT32, INTERVAL, or UUID, regardless of their contents, because Equal() in google/cloud/spanner/value.cc lacked switch cases for those types and fell through to default: return true;.

Add FLOAT32, INTERVAL, and UUID cases to Equal(), explicitly handle TYPE_CODE_UNSPECIFIED so default-constructed Value{} objects remain equal, and compare the underlying type and value protos via google::protobuf::util::MessageDifferencer::Equals in the default: branch so future unmapped type codes preserve reflexivity without silently treating unequal values as equal.

`google::cloud::spanner::Value::operator==` previously returned `true`
for any two non-NULL values of type `FLOAT32`, `INTERVAL`, or `UUID`,
regardless of their contents, because `Equal()` in
`google/cloud/spanner/value.cc` lacked `switch` cases for those types
and fell through to `default: return true;`.

Add `FLOAT32`, `INTERVAL`, and `UUID` cases to `Equal()`, explicitly
handle `TYPE_CODE_UNSPECIFIED` so default-constructed `Value{}` objects
remain equal, and change `default:` to return `false` so future unmapped
type codes fail equality checks instead of silently comparing equal.
@colinmoy
colinmoy requested a review from a team as a code owner December 1, 2026 00:34
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Dec 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for comparing FLOAT32, INTERVAL, and UUID types in spanner::Value equality checks, and updates the default comparison behavior for unknown type codes to return false instead of true. The review feedback points out that unconditionally returning false for unknown type codes in the default case violates the reflexivity requirement of operator== (i.e., a == a should be true). It is recommended to compare the underlying google::protobuf::Value fields based on kind_case() to safely handle unknown types, and to expand the unit tests to verify reflexivity for these unknown types.

Comment thread google/cloud/spanner/value.cc Resolved
Comment thread google/cloud/spanner/value_test.cc Resolved
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (67bc3a0) to head (d0e02ff).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16728      +/-   ##
==========================================
- Coverage   92.80%   92.80%   -0.01%     
==========================================
  Files        2279     2279              
  Lines      229093   229123      +30     
==========================================
+ Hits       212620   212639      +19     
- Misses      16473    16484      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@colinmoy
colinmoy enabled auto-merge (squash) December 1, 2026 18:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant