Created
August 22, 2017 13:04
-
-
Save vicenteg/f757b5f8562812855f2804f538113adf to your computer and use it in GitHub Desktop.
Shell script to extract the schema from an existing BigQuery table and output the schema in a format suitable for use with `bq mk`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z $1 ]; then | |
echo "Provide a BQ table spec, ideally fully qualified." | |
exit 1 | |
fi | |
if $(echo "" | jq .); then | |
bq --format json show $1 | jq -j '[.schema.fields[] | .name + ":" + .type] | join(",")' | |
else | |
echo "Please install jq." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment