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. Search for Cloud Spanner.
  3. Select the Cloud Spanner card.
  4. Click Enable when the API page for Cloud Spanner appears.
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. Click Continue.
  4. In the Define the database schema section, click Edit as Text.
  5. Enter the following code:
    CREATE TABLE Artists (
    ArtistId INT64 NOT NULL,
    FirstName STRING(1024),
    LastName STRING(1024),
    ArtistInfo BYTES(MAX),
    BirthDate DATE )
    PRIMARY KEY(ArtistId);
  6. Click Create.
Populate Table
  1. Select Artists in left sidebar.
  2. Review the schema.
  3. Click Data.
  4. Click Insert.
  5. Enter the following records, clicking Save after each one and then Insert:
    ArtistId = 100
    FirstName = Paul
    LastName = Cezanne
    BirthDate = 1839-01-19

    ArtistId = 101
    FirstName = Ansel
    LastName = Adams
    BirthDate = 1902-02-20
    
    ArtistId = 102
    FirstName = Frida
    LastName = Kahloe
    BirthDate = 1907-07-06
Edit Data
  1. Select the checkbox in the Frida Kahloe record.
  2. Choose Edit.
  3. Change the LastName to Kahlo.
  4. Click Save.
Query Data
  1. Choose the database from the left column.
  2. Select Query.
  3. In the Query field, enter:
    SELECT * from Artists WHERE BirthDate > ‘1900-01-01’
  4. Click Run query.
  5. 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. Navigate back to Spanner.
  6. Choose instance from left sidebar.
  7. Select Export.
  8. Select bucket to store exported data.
  9. Choose database to export.
  10. Select region.
  11. Click Confirm Charges checkbox.
  12. Click Export
  13. Visit Cloud Spanner to view progress of operation.
  14. 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?