Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
Public Member Functions | List of all members
google::cloud::spanner::v1::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:
auto commit_result = client.Commit(
[&client,
&dml_result](spanner::Transaction txn) -> StatusOr<spanner::Mutations> {
auto update = client.ProfileDml(
std::move(txn),
"UPDATE Albums SET MarketingBudget = MarketingBudget * 2"
" WHERE SingerId = 1 AND AlbumId = 1"));
if (!update) return 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";
}
}
Represents the result and profile stats of a data modifying operation using spanner::Client::ProfileD...
Definition: results.h:216
std::int64_t RowsModified() const
Returns the number of rows modified by the DML statement.
Definition: results.cc:81
absl::optional< std::unordered_map< std::string, std::string > > ExecutionStats() const
Returns a collection of key value pair statistics for the SQL statement execution.
Definition: results.cc:96
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:51
The representation of a Cloud Spanner transaction.
Definition: transaction.h:58
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 216 of file results.h.

Constructor & Destructor Documentation

◆ ProfileDmlResult() [1/3]

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

◆ ProfileDmlResult() [2/3]

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

Definition at line 219 of file results.h.

◆ ProfileDmlResult() [3/3]

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

Member Function Documentation

◆ ExecutionPlan()

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

Returns the plan of execution for the SQL statement.

Definition at line 100 of file results.cc.

◆ ExecutionStats()

absl::optional< std::unordered_map< std::string, std::string > > google::cloud::spanner::v1::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.

Definition at line 96 of file results.cc.

◆ operator=()

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

◆ RowsModified()

std::int64_t google::cloud::spanner::v1::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.

Definition at line 81 of file results.cc.