1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ # ---------------------------------------------
5+ # Enrich Snowflake ClickBench results with cost info
6+ # using a pricing JSON (standard_warehouse.json).
7+ #
8+ # Usage:
9+ # ./enrich.sh <clickbench_json> <pricing_json> <output_json> \
10+ # [--cloud <val>] [--region <val>]
11+ #
12+ # Example:
13+ # ./enrich.sh clickbench/results/4xl.json \
14+ # pricings/standard_warehouse.json \
15+ # results/4xl_enriched.json \
16+ # --cloud aws --region us-east-1
17+ #
18+ # This computes costs for *all* matching pricing plans
19+ # (standard, enterprise, business_critical, …) and writes
20+ # them into the .costs[] array, one entry per plan.
21+ # ---------------------------------------------
22+
23+ CLOUD=" aws"
24+ REGION=" us-east-1"
25+
26+ if [ " $# " -lt 3 ]; then
27+ echo " Usage: $0 <clickbench_json> <pricing_json> <output_json> [--cloud <val>] [--region <val>]" >&2
28+ exit 1
29+ fi
30+
31+ BENCH_FILE=" $1 "
32+ PRICING_FILE=" $2 "
33+ OUT_FILE=" $3 "
34+ shift 3
35+
36+ while [[ $# -gt 0 ]]; do
37+ case " $1 " in
38+ --cloud) CLOUD=" $2 " ; shift 2 ;;
39+ --region) REGION=" $2 " ; shift 2 ;;
40+ * )
41+ echo " Unknown option: $1 " >&2
42+ exit 1
43+ ;;
44+ esac
45+ done
46+
47+ if ! command -v jq > /dev/null 2>&1 ; then
48+ echo " ❌ jq is required." >&2
49+ exit 1
50+ fi
51+
52+ OUT_DIR=$( dirname " $OUT_FILE " )
53+ mkdir -p " $OUT_DIR "
54+
55+ echo " → Enriching Snowflake ClickBench results"
56+ echo " Cloud : ${CLOUD} "
57+ echo " Region: ${REGION} "
58+ echo
59+
60+ jq -s \
61+ --arg cloud " $CLOUD " \
62+ --arg region " $REGION " '
63+ .[0] as $bench |
64+ .[1] as $pricing |
65+
66+ # we use cluster_size as the "credits per hour" key
67+ # e.g. 128 → 4X-Large entry in pricing.warehouses[]
68+ ($bench.cluster_size) as $cluster_credits |
69+
70+ # build one cost entry per matching pricing block (plan)
71+ [
72+ $pricing.pricing[]
73+ | select(.cloud == $cloud and .region == $region)
74+ | . as $block
75+
76+ # find warehouse entry whose credits_per_hour == cluster_size
77+ | ($block.warehouses[]
78+ | select(.credits_per_hour == $cluster_credits)) as $wh
79+
80+ # base prices
81+ | ($block.credit_price_per_hour) as $credit_price
82+ | ($wh.credits_per_hour) as $credits_per_hour
83+
84+ # storage pricing
85+ | ($block.storage.storage) as $storage_price
86+ | ($block.storage.storage_price_unit) as $storage_unit
87+
88+ # compute costs: seconds * (credits_per_hour * credit_price / 3600)
89+ | ($bench.result
90+ | map(
91+ map(
92+ if . == null then null
93+ else (. * ($credits_per_hour * $credit_price / 3600.0))
94+ end
95+ )
96+ )
97+ ) as $compute_costs
98+
99+ # storage cost: bytes / unit * price
100+ | ($bench.data_size / $storage_unit * $storage_price) as $storage_cost
101+
102+ # one cost object per plan
103+ | {
104+ tier: .plan,
105+ provider: $cloud,
106+ service: $pricing.service,
107+ cloud: $cloud,
108+ region: $region,
109+
110+ warehouse_size: $wh.name,
111+ data_size: $bench.data_size,
112+
113+ storage_cost: $storage_cost,
114+ storage_costs: [
115+ {
116+ model: "object",
117+ term: "active",
118+ period: "monthly",
119+ price_per_byte: ($storage_price / $storage_unit),
120+ bytes: $bench.data_size,
121+ estimated_cost: $storage_cost,
122+ pricing_base: {
123+ price_usd: $storage_price,
124+ price_unit: "byte_month",
125+ price_unit_bytes: $storage_unit,
126+ notes: "Snowflake storage (list price)."
127+ }
128+ }
129+ ],
130+
131+ compute_costs: $compute_costs,
132+
133+ pricing_base: {
134+ credits_per_hour: $credits_per_hour,
135+ credit_price_per_hour: $credit_price,
136+ storage: $storage_price,
137+ storage_price_unit: $storage_unit
138+ }
139+ }
140+ ] as $all_costs
141+ | $bench + { costs: $all_costs }
142+ ' " $BENCH_FILE " " $PRICING_FILE " > " $OUT_FILE "
143+
144+ echo " ✅ Written to $OUT_FILE "
145+ echo " 💰 Total compute cost per tier:"
146+ jq -r ' .costs[]
147+ | "\(.tier): \([.compute_costs[][]] | add)"' " $OUT_FILE "
148+ echo " 💾 Storage cost (same per tier):"
149+ jq -r ' .costs[0].storage_cost' " $OUT_FILE "
0 commit comments