-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy path401-BenchmarkBigQuery.sh
executable file
·51 lines (42 loc) · 1.25 KB
/
401-BenchmarkBigQuery.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#
# NOTE: you will need to install https://www.npmjs.com/package/json to run this script
set -e
export PROJECT=billing-333723
export DATASET=tpcds_1000
# Warm-up
echo 'Warmup.sql...'
while read line;
do
echo "$line"
echo "$line" | bq --project_id=${PROJECT} --dataset_id=${DATASET} \
query \
--use_legacy_sql=false \
--batch=false \
--format=none
done < Warmup.sql
# Test
echo "Query,Started,Ended,Billing Tier,Bytes" > results/BigQueryResults.csv
for FILE in query/*.sql;
do
echo ${FILE}
QUERY=`basename ${FILE} | head -c 7`
ID=${QUERY}_$(date +%s)
cat "${FILE}" \
| bq \
--project_id=${PROJECT} \
--dataset_id=${DATASET} \
query \
--use_cache=false \
--use_legacy_sql=false \
--batch=false \
--maximum_billing_tier=10 \
--job_id=$ID \
--format=none
JOB=$(bq --project_id=${PROJECT} --format=json show -j ${ID})
STARTED=$(json statistics.startTime <<< $JOB )
ENDED=$(json statistics.endTime <<< $JOB )
BILLING_TIER=$(json statistics.query.billingTier <<< $JOB )
BYTES=$(json statistics.query.totalBytesBilled <<< $JOB )
echo "${FILE},$STARTED,$ENDED,$BILLING_TIER,$BYTES" >> results/BigQueryResults.csv
done