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
- From the Google Cloud console navigation, choose APIs & Libraries > Libraries.
- Enable the APIs for Cloud Spanner, Dataflow, and Cloud Storage.
- Create a Cloud Spanner Instance
- From the main navigation, choose Spanner in the Storage section.
- Click Create instance.
- Provide the following details:
- Name: la-spanner
- Configuration: Regional – us-central1
- Node: 1
- Click Create.
- Create Database and Table
- Click Create database.
- Name the database.
- Leave the dialect set to Google Standard SQL.
- 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); - Click Create.
- Populate Table
- Select Artists in left sidebar.
- Review the schema.
Click Data.
- Click Insert and a query window will open.
- In the values section of the query, enter the following records between the parentheses making sure to replace the example data
- Click Format Query and wait for the query to show as valid.
- 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
- Click on Data.
- Select the checkbox next to the Frida Kahloe record.
- Choose Edit.
- In the SET section of the query, change the LastName to Kahlo.
- Click Run.
- Query Data
- In the query window, click New Tab.
- In the Query field, enter:
SELECT * from Artists WHERE BirthDate > ‘1900-01-01’ - Click Run.
- Review results.
- Create Bucket and Export Data
- Navigate to Storage.
- Click Create Bucket.
- 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
- Click Create.
- Leave the public access prevention setting as the default.
- Navigate back to Spanner.
- Choose instance from left sidebar.
- Select Export.
- Select bucket to store exported data.
- Choose database to export.
- Select region.
- Click Confirm Charges checkbox.
- Click Export
- Visit Cloud Spanner to view progress of operation.
- Visit Cloud Storage bucket to confirm operation.