Created
February 21, 2022 21:12
-
-
Save rkoopmann/c0384f4f59c6bd78fe70effc8cbdd2b9 to your computer and use it in GitHub Desktop.
iterate over all views in all datasets and saving source to a local sql files
This file contains 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 | |
dataset_list="$(bq ls -n 500 | awk '{print $1}')" | |
for dataset in ${dataset_list}; do | |
view_list="$(bq ls --dataset_id ${dataset} -n 500 | awk '{if($2 == "VIEW"){print $1}}')" | |
for view in ${view_list}; do | |
echo "${dataset}.${view}" | |
bq show --format=prettyjson ${dataset}.${view} \ | |
| jq -r '.view.query' \ | |
> ${dataset}.${view}.sql | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment