Skip to content

Commit fad7885

Browse files
feat: more bigtable data filter samples (#4315)
1 parent 0bf38cf commit fad7885

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

google/cloud/bigtable/examples/data_filter_snippets.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,39 @@ void FilterComposingInterleave(google::cloud::bigtable::Table table,
449449
(std::move(table));
450450
}
451451

452+
void FilterComposingCondition(google::cloud::bigtable::Table table,
453+
std::vector<std::string> const&) {
454+
//! [START bigtable_filters_composing_condition]
455+
namespace cbt = google::cloud::bigtable;
456+
using google::cloud::StatusOr;
457+
[](cbt::Table table) {
458+
// Create the range of rows to read.
459+
auto range = cbt::RowRange::Range("key-000000", "key-000005");
460+
cbt::Filter filter = cbt::Filter::Condition(
461+
cbt::Filter::Chain(cbt::Filter::FamilyRegex("fam-0"),
462+
cbt::Filter::ColumnRegex("col-a")),
463+
cbt::Filter::ApplyLabelTransformer("condition"),
464+
cbt::Filter::StripValueTransformer());
465+
// Read and print the rows.
466+
for (StatusOr<cbt::Row> const& row : table.ReadRows(range, filter)) {
467+
if (!row) throw std::runtime_error(row.status().message());
468+
std::cout << row->row_key() << " = ";
469+
for (auto const& cell : row->cells()) {
470+
std::cout << "[" << cell.family_name() << ", "
471+
<< cell.column_qualifier() << ", " << cell.value()
472+
<< ", label(";
473+
for (auto const& label : cell.labels()) {
474+
std::cout << label << ",";
475+
}
476+
std::cout << ")],";
477+
}
478+
std::cout << "\n";
479+
}
480+
}
481+
//! [END bigtable_filters_composing_condition]
482+
(std::move(table));
483+
}
484+
452485
// This command just generates data suitable for other examples to run. This
453486
// code is not extracted into the documentation.
454487
void InsertTestData(google::cloud::bigtable::Table table,
@@ -580,6 +613,8 @@ void RunAll(std::vector<std::string> const& argv) {
580613
FilterComposingChain(table, {});
581614
std::cout << "Running FilterComposingInterleave() example [17]" << std::endl;
582615
FilterComposingInterleave(table, {});
616+
std::cout << "Running FilterComposingCondition() example [18]" << std::endl;
617+
FilterComposingCondition(table, {});
583618
admin.DeleteTable(table_id);
584619
}
585620

@@ -617,6 +652,8 @@ int main(int argc, char* argv[]) {
617652
MakeCommandEntry("filters-composing-chain", {}, FilterComposingChain),
618653
MakeCommandEntry("filters-composing-interleave", {},
619654
FilterComposingInterleave),
655+
MakeCommandEntry("filters-composing-condition", {},
656+
FilterComposingCondition),
620657
{"auto", RunAll},
621658
};
622659

0 commit comments

Comments
 (0)