Skip to content

Instantly share code, notes, and snippets.

@rkoopmann
Created February 21, 2022 21:12
Show Gist options
  • Save rkoopmann/c0384f4f59c6bd78fe70effc8cbdd2b9 to your computer and use it in GitHub Desktop.
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
#!/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