15 #include "google/cloud/spanner/query_partition.h"
16 #include <google/spanner/v1/spanner.pb.h>
24 std::string transaction_tag,
25 std::string session_id,
26 std::string partition_token,
28 : transaction_id_(std::move(transaction_id)),
29 transaction_tag_(std::move(transaction_tag)),
30 session_id_(std::move(session_id)),
31 partition_token_(std::move(partition_token)),
32 sql_statement_
(std::move(sql_statement)
) {}
35 return a.transaction_id_ == b.transaction_id_ &&
36 a.transaction_tag_ == b.transaction_tag_ &&
37 a.session_id_ == b.session_id_ &&
38 a.partition_token_ == b.partition_token_ &&
39 a.sql_statement_
== b.sql_statement_;
44 google::spanner::v1::ExecuteSqlRequest proto;
46 proto.set_partition_token(query_partition.partition_token());
47 proto.set_session(query_partition.session_id());
48 proto.mutable_transaction()->set_id(query_partition.transaction_id());
49 proto.set_sql(query_partition.sql_statement_
.sql());
50 for (
auto const& param : query_partition.sql_statement_
.params()) {
51 auto const& param_name = param.first;
52 auto const& type_value = spanner_internal::ToProto(param.second);
53 (*proto.mutable_params()->mutable_fields())[param_name] = type_value.second;
54 (*proto.mutable_param_types())[param_name] = type_value.first;
60 proto.mutable_request_options()->set_transaction_tag(
61 query_partition.transaction_tag());
63 std::string serialized_proto;
64 if (proto.SerializeToString(&serialized_proto)) {
65 return serialized_proto;
68 "Failed to serialize QueryPartition");
72 std::string
const& serialized_query_partition) {
73 google::spanner::v1::ExecuteSqlRequest proto;
74 if (!proto.ParseFromString(serialized_query_partition)) {
76 "Failed to deserialize into QueryPartition");
80 if (proto.has_params()) {
81 auto const& param_types = proto.param_types();
82 for (
auto& param : *(proto.mutable_params()->mutable_fields())) {
83 auto const& param_name = param.first;
84 auto iter = param_types.find(param_name);
85 if (iter != param_types.end()) {
86 auto const& param_type = iter->second;
87 sql_parameters.insert(std::make_pair(
89 spanner_internal::FromProto(param_type, std::move(param.second))));
95 proto.request_options().transaction_tag(),
96 proto.session(), proto.partition_token(),
98 return query_partition;