Skip to content

Instantly share code, notes, and snippets.

@mchmarny
Created December 1, 2017 21:34
Show Gist options
  • Select an option

  • Save mchmarny/2222e8aaa12c281165e9b1c3be7367cb to your computer and use it in GitHub Desktop.

Select an option

Save mchmarny/2222e8aaa12c281165e9b1c3be7367cb to your computer and use it in GitHub Desktop.
How to create Cloud Spanner database from long DDL
#!/bin/bash
# Cloud Spanner does supports DDL operations but to load a real (long) DDL
# you will wanna use something similar to this script to parse each command
# Define path to your DDL
# export SPANNER_DB_DDL="./tpch-v2-17-3.ddl"
echo 'Loading DDL...'
echo 'NOTE: empty @type property warning on return protobuf message are OK'
DDL=`cat ${SPANNER_DB_DDL} | tr -d '\n' | tr -d '\r' | tr -d '\t'`
IFS=';' read -ra LINES <<< "$DDL"
for SQL in "${LINES[@]}"; do
# echo $SQL
if [ ${#SQL} -ge 5 ]; then
gcloud spanner databases ddl update $SPANNER_DB --instance=$SPANNER_INSTANCE --ddl="$SQL"
fi
done
@mchmarny
Copy link
Copy Markdown
Author

mchmarny commented Dec 1, 2017

Alternatively, you can navigate to the Cloud Spanner UI and paste the long DDL there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment