30 Row MakeRow(std::vector<Value> values,
31 std::shared_ptr<
const std::vector<std::string>> columns) {
32 return Row(std::move(values), std::move(columns));
37 auto values = std::vector<Value>{};
38 auto columns = std::make_shared<std::vector<std::string>>();
39 for (
auto& p : pairs) {
40 values.emplace_back(std::move(p.second));
41 columns->emplace_back(std::move(p.first));
43 return internal::MakeRow(std::move(values), std::move(columns));
46 Row::Row() :
Row({}, std::make_shared<std::vector<std::string>>()) {}
49 std::shared_ptr<
const std::vector<std::string>> columns)
50 : values_(std::move(values)), columns_(std::move(columns)) {
51 if (values_.size() != columns_->size()) {
52 GCP_LOG(FATAL) <<
"Row's value and column sizes do not match: " 53 << values_.size() <<
" vs " << columns_->size();
58 StatusOr<Value>
Row::get(std::size_t pos)
const {
59 if (pos < values_.size())
return values_[pos];
60 return Status(StatusCode::kInvalidArgument,
"position out of range");
64 StatusOr<Value>
Row::get(std::string
const& name)
const {
65 auto it = std::find(columns_->begin(), columns_->end(), name);
66 if (it != columns_->end())
return get(std::distance(columns_->begin(), it));
67 return Status(StatusCode::kInvalidArgument,
"column name not found");
71 return a.values_ == b.values_ && *a.columns_ == *b.columns_;
81 : row_(
Row{}), source_(std::move(source)) {
91 if (row_ && row_->size() == 0) {
99 auto const old = *
this;
109 return !a.source_ == !b.source_;
bool operator!=(Backup const &a, Backup const &b)
std::function< StatusOr< Row >()> Source
A function that returns a sequence of StatusOr<Row> objects.
Row()
Default constructs an empty row with no columns nor values.
Row MakeTestRow(std::vector< std::pair< std::string, Value >> pairs)
Creates a Row with the specified column names and values.
RowStreamIterator()
Default constructs an "end" iterator.
bool operator==(Backup const &a, Backup const &b)
A RowStreamIterator is an Input Iterator (see below) that returns a sequence of StatusOr<Row> objects...
Contains all the Cloud Spanner C++ client types and functions.
StatusOr< Value > get(std::size_t pos) const
Returns the Value at the given pos.
A Row is a sequence of columns each with a name and an associated Value.
#define SPANNER_CLIENT_NS
RowStreamIterator & operator++()