Skip to content

Commit f9294b3

Browse files
authored
fix joins (#146)
1 parent c4aaee8 commit f9294b3

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

kokudaily/sql/key_metrics/cust_cloud_costs_data_setup.sql

+10-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ INSERT INTO __cust_cloud_cost_report (
2727
gcp_total,
2828
oci_cost
2929
)
30-
WITH aws_costs_currencies AS (
30+
WITH schemas AS (
31+
SELECT
32+
''%%1$s'' AS "customer",
33+
generate_series(date_trunc(''month'', ''%%2$s''::date), now(), ''1 day'')::date AS "date"
34+
),
35+
aws_costs_currencies AS (
3136
SELECT
3237
''%%1$s'' AS "customer",
3338
usage_start AS "date",
@@ -120,16 +125,17 @@ oci_costs AS (
120125
GROUP BY date
121126
)
122127
SELECT
123-
awc.customer AS "schema",
124-
date AS "date",
128+
s.customer AS "schema",
129+
s.date AS "date",
125130
awc.aws_unblended_cost AS "aws_unblended_cost",
126131
awc.aws_calculated_amortized_cost AS "aws_calculated_amortized_cost",
127132
azc.azure_pretax_cost AS "azure_pretax_cost",
128133
gc.gcp_unblended_cost AS "gcp_unblended_cost",
129134
gc.gcp_total AS "gcp_total",
130135
oc.oci_cost AS "oci_cost"
131136
FROM
132-
aws_costs awc
137+
schemas s
138+
FULL OUTER JOIN aws_costs awc USING (customer, date)
133139
FULL OUTER JOIN azure_costs azc USING (customer, date)
134140
FULL OUTER JOIN gcp_costs gc USING (customer, date)
135141
FULL OUTER JOIN oci_costs oc USING (customer, date)

kokudaily/sql/key_metrics/cust_openshift_costs_data_setup.sql

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ INSERT INTO __cust_openshift_cost_report (
3535
sup_cost_model_memory_cost,
3636
sup_cost_model_volume_cost
3737
)
38-
WITH infra_raw_currencies AS (
38+
WITH schemas AS (
39+
SELECT
40+
''%%1$s'' AS "customer",
41+
generate_series(date_trunc(''month'', ''%%2$s''::date), now(), ''1 day'')::date AS "date"
42+
),
43+
infra_raw_currencies AS (
3944
SELECT
4045
''%%1$s'' AS "customer",
4146
usage_start AS "date",
@@ -122,8 +127,8 @@ sup_costs AS (
122127
GROUP BY date
123128
)
124129
SELECT
125-
ir.customer AS "schema",
126-
date AS "date",
130+
s.customer AS "schema",
131+
s.date AS "date",
127132
COALESCE(ir.infrastructure_raw_cost, 0) AS "total_infrastructure_raw_cost",
128133
ic.infra_total_cost_model+sc.sup_total_cost_model AS "total_cost_model_costs",
129134
ic.infra_total_cost_model AS "infra_total_cost_model",
@@ -135,7 +140,8 @@ SELECT
135140
sc.sup_cost_model_memory_cost AS "sup_cost_model_memory_cost",
136141
sc.sup_cost_model_volume_cost AS "sup_cost_model_volume_cost"
137142
FROM
138-
infra_costs ic
143+
schemas s
144+
FULL OUTER JOIN infra_costs ic USING (customer, date)
139145
FULL OUTER JOIN infra_raw ir USING (customer, date)
140146
FULL OUTER JOIN sup_costs sc USING (customer, date)
141147
ORDER BY date

kokudaily/sql/key_metrics/cust_openshift_infra_data_setup.sql

+13-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ INSERT INTO __cust_openshift_infra_report (
5555
pvc_capacity_gb,
5656
pvc_capacity_gb_mo
5757
)
58-
with node_info as (
58+
WITH schemas AS (
59+
SELECT
60+
''%%1$s'' AS "customer",
61+
generate_series(date_trunc(''month'', ''%%2$s''::date), now(), ''1 day'')::date AS "date"
62+
),
63+
node_info as (
5964
SELECT
6065
ron.node AS node,
6166
ron.node_role AS node_role,
@@ -162,8 +167,8 @@ storage_agg AS (
162167
GROUP BY date
163168
)
164169
SELECT
165-
customer AS "schema",
166-
date,
170+
s.customer AS "schema",
171+
s.date,
167172
cluster_count,
168173
node_count,
169174
infra_node_count,
@@ -184,9 +189,11 @@ SELECT
184189
volume_request_gb_mo,
185190
pvc_capacity_gb,
186191
pvc_capacity_gb_mo
187-
FROM compute_agg c
188-
FULL OUTER JOIN storage_agg s USING (customer, date)
189-
FULL OUTER JOIN node_counts n USING (customer, date)
192+
FROM
193+
schemas s
194+
FULL OUTER JOIN compute_agg ca USING (customer, date)
195+
FULL OUTER JOIN storage_agg sa USING (customer, date)
196+
FULL OUTER JOIN node_counts nc USING (customer, date)
190197
ORDER BY date
191198
';
192199
BEGIN

0 commit comments

Comments
 (0)