Skip to content

fix(bigtable): deduplicate nested SQL MAP keys - #16655

Open
sushanb wants to merge 1 commit into
googleapis:mainfrom
sushanb:fix/bigtable-value-nested-map-dedup
Open

sushanb wants to merge 1 commit into
googleapis:mainfrom
sushanb:fix/bigtable-value-nested-map-dedup

Conversation

@sushanb

@sushanb sushanb commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Summary

bigtable::Value previously only invoked DedupProtoMap() when the top-level google::bigtable::v2::Type was map_type, and DedupProtoMap() only deduplicated entries at the top level. When a SQL MAP was nested inside an ARRAY<MAP<...>>, STRUCT<..., MAP<...>>, or outer MAP<..., MAP<...>>, duplicate keys in the nested MAP were not deduplicated with last-key-wins semantics:

  • Value::get<std::unordered_map<K, V>>() used std::unordered_map::insert, retaining the first occurrence of a duplicate key instead of the last occurrence per the google.bigtable.v2.Type.Map specification.
  • operator==, operator<<, and ToProto() retained duplicate entries in nested MAP proto representations.

Changes

  • Add TypeContainsMap() and recursive DedupProtoMaps() in google/cloud/bigtable/value.cc to deduplicate MAP entries with last-key-wins semantics across MAP, ARRAY, and STRUCT types without allocating or traversing values whose schema contains no MAP.
  • Invoke DedupProtoMap() in Value constructors for map_type, array_type, and struct_type values, and use insert_or_assign in Value::GetValue(std::unordered_map<K, V> const&, ...) as a defense-in-depth safeguard.
  • Add unit tests in value_test.cc (ProtoArrayOfMapsWithDuplicateKeys, ProtoStructWithNestedMapDuplicateKeys, ProtoNestedMapOfMapsWithDuplicateKeys) and partial_result_set_source_test.cc (NestedMapsWithDuplicateKeys).

@sushanb
sushanb requested a review from a team as a code owner November 11, 2026 21:45
@sushanb
sushanb requested a review from scotthart November 11, 2026 21:45
@product-auto-label product-auto-label Bot added the api: bigtable Issues related to the Bigtable API. label Nov 11, 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 enhances map deduplication in google::cloud::bigtable::Value by recursively handling nested maps, arrays of maps, and structs containing maps. It introduces helper functions TypeContainsMap and DedupProtoMaps, updates Value::DedupProtoMap() to use them, and switches to insert_or_assign to ensure duplicate keys are overwritten with their latest values. Comprehensive unit tests have been added to verify these changes. Feedback is provided to replace auto with explicit StatusOr types in Value::GetValue to adhere to the repository's style guide.

Comment thread google/cloud/bigtable/value.h Resolved
@sushanb
sushanb force-pushed the fix/bigtable-value-nested-map-dedup branch from 285547d to ddbdfc2 Compare November 11, 2026 21:52
@sushanb

sushanb commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 enhances the Bigtable Value class to recursively deduplicate keys in nested maps, arrays of maps, and structs containing maps. It introduces the TypeContainsMap and DedupProtoMaps helper functions to handle deep structures, updates map extraction to use insert_or_assign to ensure the last-write-wins behavior for duplicate keys, and adds comprehensive unit tests to verify these scenarios. I have no feedback to provide as the implementation is correct and conforms to the repository style guides.

@scotthart scotthart added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Nov 11, 2026
@sushanb
sushanb force-pushed the fix/bigtable-value-nested-map-dedup branch from ddbdfc2 to 73888f9 Compare November 11, 2026 22:51
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.54902% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.52%. Comparing base (5dcdef5) to head (223d0c7).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
google/cloud/bigtable/value.cc 92.06% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16655      +/-   ##
==========================================
- Coverage   92.53%   92.52%   -0.01%     
==========================================
  Files        2269     2269              
  Lines      222896   223079     +183     
==========================================
+ Hits       206250   206413     +163     
- Misses      16646    16666      +20     

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

Deduplicate duplicate keys recursively across nested MAP values (inside ARRAY, STRUCT, or outer MAP values) with last-key-wins semantics per the Bigtable Type.Map specification, and use insert_or_assign during deserialization as a defense-in-depth safeguard.
@sushanb
sushanb force-pushed the fix/bigtable-value-nested-map-dedup branch from 73888f9 to 223d0c7 Compare November 12, 2026 00:04

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: bigtable Issues related to the Bigtable API. do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants