Skip to content

Instantly share code, notes, and snippets.

@hvardhanx
Created November 25, 2019 11:35
Show Gist options
  • Save hvardhanx/44c575d73fe29dabe0464961fb9add7d to your computer and use it in GitHub Desktop.
Save hvardhanx/44c575d73fe29dabe0464961fb9add7d to your computer and use it in GitHub Desktop.
#!/bin/bash
DATASETS=$(bq ls --format=sparse | tail -n+3 | grep -v scratch)
for d in $DATASETS; do
TABLES=$(bq ls --format=prettyjson "$d" | jq '.[] | "\(.id), \(.type)"')
IFS=$'\n'
for table in $TABLES; do
[[ ! "$table" == *VIEW* ]] && continue
view=$(echo "$table" | sed -e 's/"//g' | cut -d , -f 1)
query=$(bq show --format=prettyjson "$view" | jq -r '.view.query')
echo -e "$query" > "$view.sql"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment