-
Notifications
You must be signed in to change notification settings - Fork 6
Spanner Setup Guide
Follow this guide to set up your Spanner environment for this class.
Note that we will be using the Spanner emulator so this is not a one-time set up. You'll need to redo some of the same steps each time you stop and restart the environment. The steps that are marked as skipped only need to be run the first time. The steps that are not marked, need to be run each time you restart your jupyter instance.
- Start up your Jupyter notebook instance and open a terminal window. Run the following commands in the terminal:
-
sudo apt-get install google-cloud-sdk-spanner-emulator(skip this step after initial setup) gcloud beta emulators spanner start &
Once you see Cloud Spanner emulator running, REST server listening at localhost:9020, gRPC server listening at localhost:9010, press Enter to return to the shell prompt.
-
gcloud config configurations create emulator(skip this step after initial setup)
Expected output:
Created [emulator].
Activated [emulator].
gcloud config configurations activate emulatorgcloud config set auth/disable_credentials truegcloud config set project {your_project_id}
Expected output:
Updated property [core/project].
WARNING: You do not appear to have access to project [{your_project_id}] or it does not exist.
gcloud config set api_endpoint_overrides/spanner http://localhost:9020/gcloud spanner instance-configs list
Expected output:
| NAME | DISPLAY_NAME |
|---|---|
| emulator-config | Emulator Instance Config |
gcloud spanner instances create span-instance --config=emulator-config --description="Spanner Test Instance" --nodes=1
Expected output:
Creating instance...done.
gcloud spanner databases create test-database --instance span-instance --ddl "CREATE TABLE T1 (Key INT64, Value STRING(MAX)) PRIMARY KEY (Key)"
Expected output:
Creating database...done.
-
gcloud spanner rows insert --table=T1 --database=test-database --instance=span-instance --data=Key=1,Value=TestValue1 -
gcloud spanner databases execute-sql test-database --instance span-instance --sql "select * from T1"
Expected output:
| Key | Value |
|---|---|
| 1 | TestValue1 |
curl -O https://storage.googleapis.com/golang/go1.15.2.linux-amd64.tar.gztar -xvf go1.15.2.linux-amd64.tar.gzsudo chown -R root:root ./gosudo mv go /usr/local
Add variables to your .bash_profile: (skip this section after initial setup)
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
export SPANNER_EMULATOR_HOST="localhost:9010"
source .bash_profilego help
-
go get -u github.com/cloudspannerecosystem/spanner-cli(skip this step after initial setup)
Be patient. This command may take a couple minutes to run.
spanner-cli -p {your_project_id} -i span-instance -d test-database
Expected output:
Connected.
- In the Spanner cli, run
show tables;
Expected output:
+-------------------------+
| Tables_in_test-database |
+-------------------------+
| T1 |
+-------------------------+
1 rows in set (0.00 sec)
- In the Spanner cli, run
select * from T1;
Expected output:
+-----+------------+
| Key | Value |
+-----+------------+
| 1 | TestValue1 |
+-----+------------+
1 rows in set (336.143us)
- In the Spanner cli, run
exit;to quit