Skip to content

Instantly share code, notes, and snippets.

@yaasita
Created May 8, 2020 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/c40c605e4fe9dc3ac8402d135c1f90c9 to your computer and use it in GitHub Desktop.
Save yaasita/c40c605e4fe9dc3ac8402d135c1f90c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
function recreate {
cat <<EOF > /tmp/query.sql
#standardSQL
SELECT CAST(id as STRING) as id, description FROM test.first WHERE DATE(_PARTITIONTIME) = "$1";
EOF
export partition=$(echo $1 | perl -ple 's/-//g')
cat /tmp/query.sql |
bq query --append_table --schema_update_option=ALLOW_FIELD_ADDITION \
--destination_table "test.third\$$partition" \
--time_partitioning_type DAY
}
recreate 2020-05-01
recreate 2020-05-02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment