Skip to content

Commit

Permalink
cleanup(spanner): apply some miscellaneous no-op cleanups (#10943)
Browse files Browse the repository at this point in the history
Just some random cleanups that I have been accumulating.
  • Loading branch information
devbww committed Feb 23, 2023
1 parent 9f868bf commit 2ec044f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 48 deletions.
Binary file modified ci/abi-dumps/google_cloud_cpp_spanner.expected.abi.dump.gz
Binary file not shown.
65 changes: 26 additions & 39 deletions google/cloud/spanner/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ RowStream Client::Read(std::string table, KeySet keys,
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->Read({spanner_internal::MakeSingleUseTransaction(
Transaction::ReadOnlyOptions()),
std::move(table),
std::move(keys),
std::move(columns),
std::move(table), std::move(keys), std::move(columns),
ToReadOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

RowStream Client::Read(Transaction::SingleUseOptions transaction_options,
Expand All @@ -63,22 +61,18 @@ RowStream Client::Read(Transaction::SingleUseOptions transaction_options,
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->Read({spanner_internal::MakeSingleUseTransaction(
std::move(transaction_options)),
std::move(table),
std::move(keys),
std::move(columns),
std::move(table), std::move(keys), std::move(columns),
ToReadOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

RowStream Client::Read(Transaction transaction, std::string table, KeySet keys,
std::vector<std::string> columns, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->Read({std::move(transaction),
std::move(table),
std::move(keys),
return conn_->Read({std::move(transaction), std::move(table), std::move(keys),
std::move(columns),
ToReadOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

RowStream Client::Read(ReadPartition const& read_partition, Options opts) {
Expand All @@ -90,13 +84,11 @@ StatusOr<std::vector<ReadPartition>> Client::PartitionRead(
Transaction transaction, std::string table, KeySet keys,
std::vector<std::string> columns, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->PartitionRead({{std::move(transaction),
std::move(table),
std::move(keys),
std::move(columns),
ToReadOptions(internal::CurrentOptions()),
{}},
ToPartitionOptions(internal::CurrentOptions())});
return conn_->PartitionRead(
{{std::move(transaction), std::move(table), std::move(keys),
std::move(columns), ToReadOptions(internal::CurrentOptions()),
absl::nullopt},
ToPartitionOptions(internal::CurrentOptions())});
}

RowStream Client::ExecuteQuery(SqlStatement statement, Options opts) {
Expand All @@ -105,7 +97,7 @@ RowStream Client::ExecuteQuery(SqlStatement statement, Options opts) {
Transaction::ReadOnlyOptions()),
std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

RowStream Client::ExecuteQuery(
Expand All @@ -116,16 +108,15 @@ RowStream Client::ExecuteQuery(
std::move(transaction_options)),
std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

RowStream Client::ExecuteQuery(Transaction transaction, SqlStatement statement,
Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->ExecuteQuery({std::move(transaction),
std::move(statement),
return conn_->ExecuteQuery({std::move(transaction), std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

RowStream Client::ExecuteQuery(QueryPartition const& partition, Options opts) {
Expand All @@ -140,7 +131,7 @@ ProfileQueryResult Client::ProfileQuery(SqlStatement statement, Options opts) {
Transaction::ReadOnlyOptions()),
std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

ProfileQueryResult Client::ProfileQuery(
Expand All @@ -151,16 +142,15 @@ ProfileQueryResult Client::ProfileQuery(
std::move(transaction_options)),
std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

ProfileQueryResult Client::ProfileQuery(Transaction transaction,
SqlStatement statement, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->ProfileQuery({std::move(transaction),
std::move(statement),
return conn_->ProfileQuery({std::move(transaction), std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

StatusOr<std::vector<QueryPartition>> Client::PartitionQuery(
Expand All @@ -174,30 +164,27 @@ StatusOr<std::vector<QueryPartition>> Client::PartitionQuery(
StatusOr<DmlResult> Client::ExecuteDml(Transaction transaction,
SqlStatement statement, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->ExecuteDml({std::move(transaction),
std::move(statement),
return conn_->ExecuteDml({std::move(transaction), std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

StatusOr<ProfileDmlResult> Client::ProfileDml(Transaction transaction,
SqlStatement statement,
Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->ProfileDml({std::move(transaction),
std::move(statement),
return conn_->ProfileDml({std::move(transaction), std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

StatusOr<ExecutionPlan> Client::AnalyzeSql(Transaction transaction,
SqlStatement statement,
Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), opts_));
return conn_->AnalyzeSql({std::move(transaction),
std::move(statement),
return conn_->AnalyzeSql({std::move(transaction), std::move(statement),
QueryOptions(internal::CurrentOptions()),
{}});
absl::nullopt});
}

StatusOr<BatchDmlResult> Client::ExecuteBatchDml(
Expand All @@ -221,7 +208,7 @@ StatusOr<CommitResult> Client::Commit(
auto const txn_opts = Transaction::ReadWriteOptions().WithTag(
OptOpt<TransactionTagOption>(internal::CurrentOptions()));
Transaction txn = MakeReadWriteTransaction(txn_opts);
while (true) {
for (;;) {
StatusOr<Mutations> mutations;
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
try {
Expand Down
1 change: 0 additions & 1 deletion google/cloud/spanner/internal/session_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#include "google/cloud/spanner/internal/session_pool.h"
#include "google/cloud/spanner/internal/connection_impl.h"
#include "google/cloud/spanner/internal/session.h"
#include "google/cloud/spanner/internal/status_utils.h"
#include "google/cloud/spanner/options.h"
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/query_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ StatusOr<QueryPartition> DeserializeQueryPartition(
* The `QueryPartition` class is a regular type that represents a single slice
* of a parallel SQL read.
*
* Instances of `QueryPartition` are created by `Client::PartitionSql`. Once
* Instances of `QueryPartition` are created by `Client::PartitionQuery`. Once
* created, `QueryPartition` objects can be serialized, transmitted to separate
* process, and used to read data in parallel using `Client::ExecuteQuery`.
* processes, and used to read data in parallel using `Client::ExecuteQuery`.
*/
class QueryPartition {
public:
Expand Down
4 changes: 0 additions & 4 deletions google/cloud/spanner/read_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ bool operator==(ReadPartition const& lhs, ReadPartition const& rhs) {
return differencer.Compare(lhs.proto_, rhs.proto_);
}

bool operator!=(ReadPartition const& lhs, ReadPartition const& rhs) {
return !(lhs == rhs);
}

StatusOr<std::string> SerializeReadPartition(
ReadPartition const& read_partition) {
std::string serialized_proto;
Expand Down
4 changes: 3 additions & 1 deletion google/cloud/spanner/read_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class ReadPartition {
/// @name Equality
///@{
friend bool operator==(ReadPartition const& lhs, ReadPartition const& rhs);
friend bool operator!=(ReadPartition const& lhs, ReadPartition const& rhs);
friend bool operator!=(ReadPartition const& lhs, ReadPartition const& rhs) {
return !(lhs == rhs);
}
///@}

private:
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/spanner/read_partition_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class ReadPartitionTester {
ReadPartitionTester() = default;
explicit ReadPartitionTester(spanner::ReadPartition partition)
: partition_(std::move(partition)) {}
spanner::ReadPartition Partition() const { return partition_; }
std::string PartitionToken() const { return partition_.PartitionToken(); }
std::string SessionId() const { return partition_.SessionId(); }
std::string TransactionId() const { return partition_.TransactionId(); }
bool RouteToLeader() const { return partition_.RouteToLeader(); }
std::string TransactionTag() const { return partition_.TransactionTag(); }
spanner::ReadPartition Partition() const { return partition_; }
std::string TableName() const { return partition_.TableName(); }
google::spanner::v1::KeySet KeySet() const { return partition_.KeySet(); }
std::vector<std::string> ColumnNames() const {
Expand Down
3 changes: 3 additions & 0 deletions google/cloud/spanner/samples/samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2492,6 +2492,9 @@ void UsePartitionQuery(google::cloud::spanner::Client client) {
auto partitions =
client.PartitionQuery(std::move(txn), std::move(select), {});
if (!partitions) throw std::move(partitions).status();

// You would probably choose to execute these partitioned queries in
// separate threads/processes, or on a different machine.
int number_of_rows = 0;
for (auto const& partition : *partitions) {
auto rows = client.ExecuteQuery(partition);
Expand Down

0 comments on commit 2ec044f

Please sign in to comment.