Skip to content

chore(bigtable): migrate to std::optional#16215

Merged
scotthart merged 3 commits into
googleapis:mainfrom
colinmoy:migrate-bigtable-optional
Jun 30, 2026
Merged

chore(bigtable): migrate to std::optional#16215
scotthart merged 3 commits into
googleapis:mainfrom
colinmoy:migrate-bigtable-optional

Conversation

@colinmoy

Copy link
Copy Markdown
Contributor

Replacing explicit usages of absl::optional with std::optional in the Bigtable Client library as part of broader modernization efforts

@colinmoy colinmoy requested a review from a team as a code owner June 29, 2026 18:38
@colinmoy colinmoy changed the title Migrate bigtable optional chore(bigtable): migrate to std::optional Jun 29, 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 migrates the codebase from absl::optional to C++17's std::optional (along with corresponding changes to nullopt and make_optional) across multiple BigQuery and Bigtable files. Feedback on the changes highlights a safety issue in google/cloud/bigtable/internal/data_connection_impl.cc, where source_ is dereferenced without checking if the underlying StatusOr is OK, potentially leading to undefined behavior or assertion failures.

Comment on lines +1009 to 1012
std::optional<google::bigtable::v2::ResultSetMetadata> Metadata() override {
if (!source_.has_value()) return std::nullopt;
return (**source_)->Metadata();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Dereferencing source_ (which is a std::optional<StatusOr<...>>) when the underlying StatusOr is not OK results in undefined behavior or an assertion failure. Since Metadata() returns a std::optional, we should safely return std::nullopt if source_ is not OK.

  std::optional<google::bigtable::v2::ResultSetMetadata> Metadata() override {
    if (!source_.has_value() || !source_->ok()) return std::nullopt;
    return (**source_)->Metadata();
  }
References
  1. Scrutinize Edge Cases: Always consider failure modes. Do not assume a perfect world. Also, never ignore Status types. (link)
  2. Prefer defensive code, such as explicit ok() checks, even if they seem redundant based on the current implementation of a framework, as the framework's contract may change in the future.

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.71362% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.24%. Comparing base (f1a8e57) to head (046e57c).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...le/cloud/bigtable/internal/data_connection_impl.cc 66.66% 2 Missing ⚠️
google/cloud/bigtable/internal/metrics.cc 66.66% 2 Missing ⚠️
...loud/bigtable/internal/partial_result_set_source.h 0.00% 2 Missing ⚠️
...ogle/cloud/bigtable/tests/data_integration_test.cc 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16215   +/-   ##
=======================================
  Coverage   92.23%   92.24%           
=======================================
  Files        2265     2265           
  Lines      210205   210210    +5     
=======================================
+ Hits       193888   193899   +11     
+ Misses      16317    16311    -6     

☔ 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 force-pushed the migrate-bigtable-optional branch 3 times, most recently from 248d4a2 to cd20806 Compare June 29, 2026 20:42
@scotthart scotthart merged commit 559b727 into googleapis:main Jun 30, 2026
62 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants