Google Cloud Spanner C++ Client  1.42.0
A C++ Client Library for Google Cloud Spanner
Public Member Functions | List of all members
google::cloud::spanner::ProfileDmlResult Class Reference

Represents the result and profile stats of a data modifying operation using spanner::Client::ProfileDml(). More...

#include <google/cloud/spanner/results.h>

Public Member Functions

 ProfileDmlResult ()=default
 
 ProfileDmlResult (std::unique_ptr< spanner_internal::ResultSourceInterface > source)
 
 ProfileDmlResult (ProfileDmlResult &&)=default
 
ProfileDmlResultoperator= (ProfileDmlResult &&)=default
 
std::int64_t RowsModified () const
 Returns the number of rows modified by the DML statement. More...
 
absl::optional< std::unordered_map< std::string, std::string > > ExecutionStats () const
 Returns a collection of key value pair statistics for the SQL statement execution. More...
 
absl::optional< spanner::ExecutionPlanExecutionPlan () const
 Returns the plan of execution for the SQL statement. More...
 

Detailed Description

Represents the result and profile stats of a data modifying operation using spanner::Client::ProfileDml().

This class encapsulates the result of a Cloud Spanner DML operation, i.e., INSERT, UPDATE, or DELETE.

Note
ProfileDmlResult returns the number of rows modified, execution statistics, and query plan.
Example:
spanner::ProfileDmlResult dml_result;
auto commit_result = client.Commit(
[&client,
&dml_result](spanner::Transaction txn) -> StatusOr<spanner::Mutations> {
auto update = client.ProfileDml(
std::move(txn),
spanner::SqlStatement(
"UPDATE Albums SET MarketingBudget = MarketingBudget * 2"
" WHERE SingerId = 1 AND AlbumId = 1"));
if (!update) return std::move(update).status();
dml_result = *std::move(update);
});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
// Stats only available after statement has been executed.
std::cout << "Rows modified: " << dml_result.RowsModified();
auto execution_stats = dml_result.ExecutionStats();
if (execution_stats) {
for (auto const& stat : *execution_stats) {
std::cout << stat.first << ":\t" << stat.second << "\n";
}
}
std::vector< Mutation > Mutations
An ordered sequence of mutations to pass to Client::Commit() or return from the Client::Commit() muta...
Definition: mutations.h:99

Definition at line 217 of file results.h.

Constructor & Destructor Documentation

◆ ProfileDmlResult() [1/3]

google::cloud::spanner::ProfileDmlResult::ProfileDmlResult ( )
default

◆ ProfileDmlResult() [2/3]

google::cloud::spanner::ProfileDmlResult::ProfileDmlResult ( std::unique_ptr< spanner_internal::ResultSourceInterface >  source)
inlineexplicit

Definition at line 220 of file results.h.

◆ ProfileDmlResult() [3/3]

google::cloud::spanner::ProfileDmlResult::ProfileDmlResult ( ProfileDmlResult &&  )
default

Member Function Documentation

◆ ExecutionPlan()

absl::optional<spanner::ExecutionPlan> google::cloud::spanner::ProfileDmlResult::ExecutionPlan ( ) const

Returns the plan of execution for the SQL statement.

◆ ExecutionStats()

absl::optional<std::unordered_map<std::string, std::string> > google::cloud::spanner::ProfileDmlResult::ExecutionStats ( ) const

Returns a collection of key value pair statistics for the SQL statement execution.

Note
Only available when the SQL statement is executed.

◆ operator=()

ProfileDmlResult& google::cloud::spanner::ProfileDmlResult::operator= ( ProfileDmlResult &&  )
default

◆ RowsModified()

std::int64_t google::cloud::spanner::ProfileDmlResult::RowsModified ( ) const

Returns the number of rows modified by the DML statement.

Note
Partitioned DML only provides a lower bound of the rows modified, all other DML statements provide an exact count.