Setting Up for Google Cloud Spanner

30 minutes
  • 7 Learning Objectives

About this Hands-on Lab

Today’s global companies require a global solution for their extensive data needs. Cloud Spanner provides a highly available, SQL-compliant database solution capable of scaling horizontally on a planet-wide scale. In this hands-on lab, you’ll walk through the process of establishing a Cloud Spanner instance and then creating a populated database to manage: from querying data to exporting it to Google Cloud Storage.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Enable APIs
  1. From the Google Cloud console navigation, choose APIs & Libraries > Libraries.
  2. Enable the APIs for Cloud Spanner, Dataflow, and Cloud Storage.
Create a Cloud Spanner Instance
  1. From the main navigation, choose Spanner in the Storage section.
  2. Click Create instance.
  3. Provide the following details:
    • Name: la-spanner
    • Configuration: Regional – us-central1
    • Node: 1
  4. Click Create.
Create Database and Table
  1. Click Create database.
  2. Name the database.
  3. Leave the dialect set to Google Standard SQL.
  4. In the Define your schema section enter the following code in the DDL statements box:
    CREATE TABLE Artists (
    ArtistId INT64 NOT NULL,
    FirstName STRING(1024),
    LastName STRING(1024),
    BirthDate DATE )
    PRIMARY KEY(ArtistId);
  5. Click Create.
Populate Table
  1. Select Artists in left sidebar.
  2. Review the schema.
  3. Click Data.

    1. Click Insert and a query window will open.
    2. In the values section of the query, enter the following records between the parentheses making sure to replace the example data
    3. Click Format Query and wait for the query to show as valid.
    4. Click Run:
      
      100,
      "Paul",
      "Cezanne",
      DATE("1839-01-19")

    101,
    "Ansel",
    "Adams",
    DATE("1902-02-20")

    102,
    "Frida",
    "Kahloe",
    DATE("1907-07-06")

Edit Data
  1. Click on Data.
  2. Select the checkbox next to the Frida Kahloe record.
  3. Choose Edit.
  4. In the SET section of the query, change the LastName to Kahlo.
  5. Click Run.
Query Data
  1. In the query window, click New Tab.
  2. In the Query field, enter:
    SELECT * from Artists WHERE BirthDate > ‘1900-01-01’
  3. Click Run.
  4. Review results.
Create Bucket and Export Data
  1. Navigate to Storage.
  2. Click Create Bucket.
  3. Provide the following details:
    • Name: la-spanner-export-<INSERT NUMBERS OR LETTERS HERE> (must be unique across all Cloud Storage)
    • Default storage class: Regional
    • Location: us-central1
  4. Click Create.
  5. Leave the public access prevention setting as the default.
  6. Navigate back to Spanner.
  7. Choose instance from left sidebar.
  8. Select Export.
  9. Select bucket to store exported data.
  10. Choose database to export.
  11. Select region.
  12. Click Confirm Charges checkbox.
  13. Click Export
  14. Visit Cloud Spanner to view progress of operation.
  15. Visit Cloud Storage bucket to confirm operation.

Additional Resources

You’ve been asked to get familiar with Cloud Spanner in advance of the company migrating a significant portion of its data to the service. To do so, you’ll need to go through the steps of creating a Cloud Spanner instance and the various operations from creating a database with a sample populated table, running a query on the data, and then exporting it into Avro format.

To accomplish this task, you’ll need to complete the following steps:

  1. Enable the Cloud Spanner API.
  2. Create a Cloud Spanner instance.
  3. Create a database.
  4. Create a schema for a database table.
  5. Populate the table with data.
  6. Edit the data.
  7. Run a query on the data.
  8. Export the data to Cloud Storage.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?