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.
- Search for Cloud Spanner.
- Select the Cloud Spanner card.
- Click Enable when the API page for Cloud Spanner appears.
- 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.
- Click Continue.
- In the Define the database schema section, click Edit as Text.
- 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); - Click Create.
- Populate Table
- Select Artists in left sidebar.
- Review the schema.
- Click Data.
- Click Insert.
Enter the following records, clicking Save after each one and then Insert:
ArtistId = 100
FirstName = Paul
LastName = Cezanne
BirthDate = 1839-01-19ArtistId = 101 FirstName = Ansel LastName = Adams BirthDate = 1902-02-20 ArtistId = 102 FirstName = Frida LastName = Kahloe BirthDate = 1907-07-06
- Edit Data
- Select the checkbox in the Frida Kahloe record.
- Choose Edit.
- Change the LastName to Kahlo.
- Click Save.
- Query Data
- Choose the database from the left column.
- Select Query.
- In the Query field, enter:
SELECT * from Artists WHERE BirthDate > ‘1900-01-01’ - Click Run query.
- 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.
- 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.