Repository navigation
Conversation
`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.
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
google::cloud::spanner::Value::operator==previously returnedtruefor any two non-NULL values of typeFLOAT32,INTERVAL, orUUID, regardless of their contents, becauseEqual()ingoogle/cloud/spanner/value.cclackedswitchcases for those types and fell through todefault: return true;.Add
FLOAT32,INTERVAL, andUUIDcases toEqual(), explicitly handleTYPE_CODE_UNSPECIFIEDso default-constructedValue{}objects remain equal, and compare the underlying type and value protos viagoogle::protobuf::util::MessageDifferencer::Equalsin thedefault:branch so future unmapped type codes preserve reflexivity without silently treating unequal values as equal.