Not SQL but a possible solution is using the bq
tool. Describing a table will return the number of Long Term Storage bytes (numLongTermBytes
):
$ bq show --format=prettyjson dataset.table
...
"kind": "bigquery#table",
"lastModifiedTime": "1534845362446",
"location": "US",
"numBytes": "56",
"numLongTermBytes": "56",
"numRows": "3",
...
Therefore, you can extend it to list all tables in each dataset and get the desired information from each. Based from this I did a quick example:
#!/bin/bash
project=PROJECT_ID
dataset=DATASET_NAME
max_results=100
# get list of tables
tables=$(bq ls --max_results $max_results "$project:$dataset" | awk '{print $1}' | tail -n +3)
# get LTS bytes for each table
for table in $tables
do
printf '%-35s %-50s\n' "$table" "$(bq show --format prettyjson $project:$dataset.$table | grep numLongTermBytes)"
done
and you'll get an output similar to:
Dfp "numLongTermBytes": "0",
SO_55506947 "numLongTermBytes": "144",
SO_55506947_bis "numLongTermBytes": "144",
a "numLongTermBytes": "7",
a1 "numLongTermBytes": "399",
aaa "numLongTermBytes": "8",
adaptive "numLongTermBytes": "1085",
adaptive_view "numLongTermBytes": "0",
audience_segment_map_exp_test "numLongTermBytes": "300",
b "numLongTermBytes": "7",
...