15 #include "google/cloud/spanner/results.h"
16 #include "absl/types/optional.h"
17 #include <google/spanner/v1/result_set.pb.h>
20 #include <unordered_map>
28 absl::optional<
Timestamp> GetReadTimestamp(
29 std::unique_ptr<spanner_internal::ResultSourceInterface>
const& source) {
30 auto metadata = source->Metadata();
32 if (metadata.has_value() && metadata->has_transaction() &&
33 metadata->transaction().has_read_timestamp()) {
35 if (ts) timestamp =
*std::move(ts);
40 std::int64_t GetRowsModified(
41 std::unique_ptr<spanner_internal::ResultSourceInterface>
const& source) {
42 return source->Stats()->row_count_exact();
45 absl::optional<std::unordered_map<std::string, std::string>> GetExecutionStats(
46 std::unique_ptr<spanner_internal::ResultSourceInterface>
const& source) {
47 auto stats = source->Stats();
48 if (stats && stats->has_query_stats()) {
49 std::unordered_map<std::string, std::string> execution_stats;
50 for (
auto const& entry : stats->query_stats().fields()) {
51 execution_stats.insert(
52 std::make_pair(entry.first, entry.second.string_value()));
54 return execution_stats;
59 absl::optional<
spanner::ExecutionPlan> GetExecutionPlan(
60 std::unique_ptr<spanner_internal::ResultSourceInterface>
const& source) {
61 auto stats = source->Stats();
62 if (stats && stats->has_query_plan()) {
63 return source->Stats()->query_plan();
70 return GetReadTimestamp(source_);
74 return GetReadTimestamp(source_);
78 return GetRowsModified(source_);
82 return GetRowsModified(source_);
85 absl::optional<std::unordered_map<std::string, std::string>>
87 return GetExecutionStats(source_);
92 return GetExecutionPlan(source_);
95 absl::optional<std::unordered_map<std::string, std::string>>
97 return GetExecutionStats(source_);
101 return GetExecutionPlan(source_);