Bigtable

To store our data, we need the support of Cloud Storage. We can use three different data storage services—Cloud BigQuery, Cloud Bigtable, and Cloud Datastore. To store time-series, Google suggest that you use Bigtable. Bigtable is very similar to the popular open source platform Apache HBase. Bigtable is organized in tables, rows, columns, and families of columns:

  • A table is a collection of rows
  • A row is a collection of column families
  • A column family is a collection of columns
  • A column is a collection of key value pairs

In our exercise, we are going to build a schema, where a combination of device IDs and timestamps is the row key and the column families are the sensors. Please look into the layout and the content of the following table:

 

Column family

Column family

 

sensor1

sensor2

Row key

Column

Column

Column

Column

Deviceid#Timestamp

Value

Quality

Value

Quality

 

Because Cloud Bigtable tables are sparse, you can create as many column qualifiers as you need in each row. There is no penalty for having empty cells in a row. For a detailed explanation of Bigtable schema please visit https://cloud.google.com/bigtable/docs/schema-design  and https://cloud.google.com/bigtable/docs/schema-design-time-series

Before starting our deployment, we can test Bigtable locally using the GCP Bigtable emulator. To run the Bigtable emulator, we need to launch the following command:

$ gcloud beta emulators bigtable start

When the Bigtable has been started, we can execute the following command:

$ export BIGTABLE_EMULATOR_HOST=localhost:8086
$ cbt -project iiot-book-local -instance iiot-book-data createtable iiot-book-signals
$ cbt -project iiot-book-local -instance iiot-book-data createfamily iiot-book-signals signal1

The first line forces the Bigtable command-line tool cbt to use a local emulator. The second line creates a table called iiot-book-signals. The third line names our first column family signal1.

We can now store our first record as follows:

$ cbt -project iiot-book-local -instance iiot-book-data set iiot-book-signals my-iiot-device#1531639262000 signal1:value=13.0 signal1:quality='GOOD'

To read it, use the following command:

$ cbt -project iiot-book-local -instance iiot-book-data read iiot-book-signals

We can now build our Bigtable in the cloud. Follow these steps:

  1. We need to create an instance from the left-hand menu of the GCP homepage:

Creating an instance of Bigtable
  1. Now, we can define the instance name as iiot-book-storage. Select the instance type as Development, as shown in the following screenshot:

 Creating an instance of Bigtable

Due to the high cost of Bigtable, we suggest that you drop the instance that we just created after the exercise.

To create the data table, we can either use the UI or the cbt script. In this exercise, we will use the cbt tool.

  1. We need to open a new Command Prompt and execute the following command:
$ cbt -project iiot-book-<id> -instance iiot-book-storage createtable iiot-book-signals
% cbt -project iiot-book-<id> -instance iiot-book-storage createfamily iiot-book-signals signal1
  1. Finally we can check the creation of the table with the following command:
$ cbt -project iiot-book-<id> -instance iiot-book-storage ls iiot-book-signals
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset