|
| 1 | +/*! |
| 2 | +@page bigtable-hello-world Example: C++ Hello World Application |
| 3 | + |
| 4 | +This example is a very simple "hello world" application, written in C++, that |
| 5 | +illustrates how to: |
| 6 | + |
| 7 | +- Connect to a Cloud Bigtable instance. |
| 8 | +- Create a new table. |
| 9 | +- Write data to the table. |
| 10 | +- Read the data back. |
| 11 | +- Delete the table. |
| 12 | + |
| 13 | +## Running the example |
| 14 | + |
| 15 | +This example uses the |
| 16 | +[Cloud Bigtable C++ Client Library](https://GoogleCloudPlatform.github.io/google-cloud-cpp) |
| 17 | +to communicate with Cloud Bigtable. |
| 18 | + |
| 19 | +To run the example program, follow the |
| 20 | +[instructions](https://github.com/GoogleCloudPlatform/google-cloud-cpp/tree/master/bigtable/examples/) |
| 21 | +for the example on GitHub. |
| 22 | + |
| 23 | +### Including the Necessary Headers |
| 24 | + |
| 25 | +The example uses the following headers: |
| 26 | + |
| 27 | +@snippet bigtable_hello_world.cc bigtable includes |
| 28 | + |
| 29 | +### Connecting to Cloud Bigtable to manage tables |
| 30 | + |
| 31 | +To manage tables, connect to Cloud Bigtable using |
| 32 | +`bigtable::CreateDefaultAdminClient()`: |
| 33 | + |
| 34 | +@snippet bigtable_hello_world.cc connect admin |
| 35 | + |
| 36 | +### Creating a table |
| 37 | + |
| 38 | +Create a table with `bigtable::TableAdmin::CreateTable()`: |
| 39 | + |
| 40 | +@snippet bigtable_hello_world.cc create table |
| 41 | + |
| 42 | +@see `bigtable::v0::TableAdmin` for additional operations to list, read, modify, |
| 43 | +and delete tables. |
| 44 | + |
| 45 | +### Connecting to Cloud Bigtable to manage data |
| 46 | + |
| 47 | +To manage data, connect to Cloud Bigtable using |
| 48 | +`bigtable::CreateDefaultDataClient()`: |
| 49 | + |
| 50 | +@snippet bigtable_hello_world.cc connect data |
| 51 | + |
| 52 | +### Writing Rows to a table |
| 53 | + |
| 54 | +Then write the data: |
| 55 | + |
| 56 | +@snippet bigtable_hello_world.cc write rows |
| 57 | + |
| 58 | +@see `bigtable::v0::Table::BulkApply()` to modify multiple rows in a single |
| 59 | +operation. In addition to `SetCell()` there |
| 60 | +are functions to delete columns (e.g., `DeleteFromFamily()`) or to delete the |
| 61 | +whole row (`DeleteFromRow()`). |
| 62 | + |
| 63 | +### Reading a row by its key |
| 64 | + |
| 65 | +Get a row directly using its key with `bigtable::Table::ReadRow()`: |
| 66 | + |
| 67 | +@snippet bigtable_hello_world.cc read row |
| 68 | + |
| 69 | +@see `bigtable::v0::Filter` to filter the column families, columns, and even |
| 70 | + the timestamps returned by `ReadRow()`. |
| 71 | +@see `bigtable::v0::Table::ReadRows()` to iterate over multiple rows. |
| 72 | + |
| 73 | +### Scanning all table rows |
| 74 | + |
| 75 | +Use `bigtable::Table::ReadRows()` to scan all of the rows in a table. |
| 76 | + |
| 77 | +@snippet bigtable_hello_world.cc scan all |
| 78 | + |
| 79 | +@see `bigtable::v0::RowRange` to scan only a portion of the table. |
| 80 | + |
| 81 | +### Deleting a table |
| 82 | + |
| 83 | +Delete a table with `TableAdmin::DeleteTable`. |
| 84 | + |
| 85 | +@snippet bigtable_hello_world.cc delete table |
| 86 | + |
| 87 | +## Putting it all together |
| 88 | + |
| 89 | +Here is the full example |
| 90 | + |
| 91 | +@snippet bigtable_hello_world.cc all code |
| 92 | +*/ |
0 commit comments