Create a test table

This page describes the steps to create a small Bigtable table that you can use to test code snippets. The table contains time-series data for smartphones and tablets.

These instructions use the Google Cloud console and the cbt CLI , a command-line interface built specifically for Bigtable.

Before you begin

Before creating a test table, complete the following prerequisites.

Set up authentication

You can use the gcloud CLI samples on this page from either of the following development environments:

  • Cloud Shell: To use an online terminal with the gcloud CLI already set up, activate Cloud Shell.

    At the bottom of this page, a Cloud Shell session starts and displays a command-line prompt. It can take a few seconds for the session to initialize.

  • Local shell: To use the gcloud CLI in a local development environment, install and initialize the gcloud CLI.

For information about setting up authentication for a production environment, see Set up Application Default Credentials for code running on Google Cloud.

Grant IAM role

To get the permissions that you need to create a test table, ask your administrator to grant you the Bigtable Administrator (roles/bigtable.admin) IAM role on your project. For more information about granting roles, see Manage access.

You might also be able to get the required permissions through custom roles or other predefined roles.

Install the cbt CLI

Run the following command to install the cbt CLI :

  gcloud components install cbt

Create an instance

In the project of your choice, create a test instance to store your test table. The table is small, so you only need a single-node instance.

  1. Open the Create instance page in the Google Cloud console.

    Create an instance

  2. For Instance name, enter Test instance.

  3. For Instance ID, enter test-instance.

  4. For Storage type, select SSD.

  5. For Cluster ID, enter test-instance-c1.

  6. For Region, select a region near you.

  7. For Zone, select a zone in the region you selected.

  8. Under Nodes, enter 1.

  9. Click Create to create the instance.

Connect to the instance

  1. Configure the cbt CLI to use your project and instance by creating a .cbtrc file, replacing PROJECT_ID with the ID for the project where you created your Bigtable instance:

    echo project = PROJECT_ID >> ~/.cbtrc && echo instance = test-instance >> ~/.cbtrc
    
  2. Verify that you set up the .cbtrc file correctly:

    cat ~/.cbtrc

    The terminal displays the contents of the .cbtrc file, which looks similar to the following:

    project = PROJECT_ID
    instance = test-instance

    Now you can use the cbt CLI with your instance.

Create a test table

  1. Create a table named test-table that has two column families. For each column family, set a garbage collection policy to keep a maximum of 2 cells per column:

       cbt createtable test-table "families=stats_summary:maxversions=2,stats_detail:maxversions=2,cell_plan:maxversions=2"

  2. List the column families:

       cbt ls test-table

    The terminal displays output similar to the following:

        Family Name       GC Policy
        -----------       ---------
        stats_detail        versions() > 2
        stats_summary       versions() > 2
        cell_plan           versions() > 2

Populate the table

  1. Copy the following commands into your terminal window and press Enter.

       cbt set test-table phone#4c410523#20190501 stats_summary:connected_cell=1 stats_summary:connected_wifi=1 stats_summary:os_build=PQ2A.190405.003 cell_plan:data_plan_01gb=true cell_plan:data_plan_05gb=true
        cbt set test-table phone#4c410523#20190502 stats_summary:connected_cell=1 stats_summary:connected_wifi=1 stats_summary:os_build=PQ2A.190405.004 cell_plan:data_plan_05gb=true
        cbt set test-table phone#4c410523#20190505 stats_summary:connected_cell=0 stats_summary:connected_wifi=1 stats_summary:os_build=PQ2A.190406.000
        cbt set test-table phone#5c10102#20190501 stats_summary:connected_cell=1 stats_summary:connected_wifi=1 stats_summary:os_build=PQ2A.190401.002 cell_plan:data_plan_10gb=true
        cbt set test-table tablet#5c10102#20190502 stats_summary:connected_cell=1 stats_summary:connected_wifi=0 stats_summary:os_build=PQ2A.190406.000 cell_plan:data_plan_10gb=true

  2. Use the cbt read command to read the data you added to the table:

       cbt read test-table

    The terminal displays output similar to the following. Note that timestamps are automatically assigned to cells because your write request does not include timestamps.

        ----------------------------------------
        phone#4c410523#20190501
          cell_plan:data_plan_01gb                 @ 2020/09/23-11:44:10.535000
            "true"
          cell_plan:data_plan_05gb                 @ 2020/09/23-11:44:10.535000
            "true"
          stats_summary:connected_cell             @ 2020/09/23-11:44:10.535000
            "1"
          stats_summary:connected_wifi             @ 2020/09/23-11:44:10.535000
            "1"
          stats_summary:os_build                   @ 2020/09/23-11:44:10.535000
            "PQ2A.190405.003"
        ----------------------------------------
        phone#4c410523#20190502
          cell_plan:data_plan_05gb                 @ 2020/09/23-11:44:11.545000
            "true"
          stats_summary:connected_cell             @ 2020/09/23-11:44:11.545000
            "1"
          stats_summary:connected_wifi             @ 2020/09/23-11:44:11.545000
            "1"
          stats_summary:os_build                   @ 2020/09/23-11:44:11.545000
            "PQ2A.190405.004"
        ----------------------------------------
        phone#4c410523#20190505
    stats_summary:connected_cell @ 2020/09/23-11:44:12.503000 "0" stats_summary:connected_wifi @ 2020/09/23-11:44:12.503000 "1" stats_summary:os_build @ 2020/09/23-11:44:12.503000 "PQ2A.190406.000" ---------------------------------------- phone#5c10102#20190501 cell_plan:data_plan_10gb @ 2020/09/23-11:44:13.553000 "true" stats_summary:connected_cell @ 2020/09/23-11:44:13.553000 "1" stats_summary:connected_wifi @ 2020/09/23-11:44:13.553000 "1" stats_summary:os_build @ 2020/09/23-11:44:13.553000 "PQ2A.190401.002" ---------------------------------------- tablet#5c10102#20190502 cell_plan:data_plan_10gb @ 2020/09/23-11:44:14.480000 "true" stats_summary:connected_cell @ 2020/09/23-11:44:14.480000 "1" stats_summary:connected_wifi @ 2020/09/23-11:44:14.480000 "0" stats_summary:os_build @ 2020/09/23-11:44:14.480000 "PQ2A.190406.000"

Use the test data

You can now use the test-table on the test-instance to try code snippets, such as those found on Using Bigtable with Cloud Functions.

Clean up

To avoid incurring charges to your Google Cloud account for the resources created during these steps, delete the instance as soon as you finish testing. Deleting the .cbtrc file leaves you ready to work on a different project.

  1. If you want to keep the instance but delete the table, you can use the deletetable command:

       cbt deletetable test-table

  2. If you don't plan to use the instance for further testing, delete the instance. This action also deletes the table.

       cbt deleteinstance test-instance

  3. Delete the .cbtrc file:

       rm ~/.cbtrc

What's next