Skip to content

Commit 38946b4

Browse files
lcouzensmyersCody
andauthored
adding year month to disk join where clause (#5443)
--------- Co-authored-by: myersCody <[email protected]> Co-authored-by: Cody Myers <[email protected]>
1 parent fd3f76e commit 38946b4

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql

+17-9
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ JOIN hive.{{schema | sqlsafe}}.aws_openshift_daily_resource_matched_temp as aws
684684
JOIN hive.{{schema | sqlsafe}}.aws_openshift_disk_capacities_temp AS aws_disk
685685
ON aws_disk.usage_start = aws.usage_start
686686
AND aws_disk.resource_id = aws.resource_id
687-
AND aws_disk.ocp_source = {{ocp_source_uuid}}
688687
WHERE ocp.source = {{ocp_source_uuid}}
689688
AND ocp.year = {{year}}
690689
AND lpad(ocp.month, 2, '0') = {{month}} -- Zero pad the month when fewer than 2 characters
@@ -697,6 +696,9 @@ WHERE ocp.source = {{ocp_source_uuid}}
697696
AND aws.data_transfer_direction IS NULL
698697
AND ocp.namespace != 'Storage unattributed'
699698
AND aws.resource_id_matched = True
699+
AND aws_disk.year = {{year}}
700+
AND aws_disk.month = {{month}}
701+
AND aws_disk.ocp_source = {{ocp_source_uuid}}
700702
GROUP BY aws.uuid, ocp.namespace, ocp.pod_labels, ocp.volume_labels
701703
{% endif %}
702704
;
@@ -749,15 +751,17 @@ WITH cte_total_pv_capacity as (
749751
aws.resource_id as aws_resource_id
750752
FROM hive.{{schema | sqlsafe}}.reporting_ocpusagelineitem_daily_summary as ocp
751753
JOIN hive.{{schema | sqlsafe}}.aws_openshift_daily_resource_matched_temp as aws
752-
ON (aws.usage_start = ocp.usage_start)
753-
AND strpos(aws.resource_id, ocp.csi_volume_handle) > 0
754-
AND ocp.csi_volume_handle is not null
755-
AND ocp.csi_volume_handle != ''
756-
WHERE ocp.source = {{ocp_source_uuid}}
757-
AND ocp.year = {{year}}
754+
ON (aws.usage_start = ocp.usage_start)
755+
AND strpos(aws.resource_id, ocp.csi_volume_handle) > 0
756+
AND ocp.csi_volume_handle is not null
757+
AND ocp.csi_volume_handle != ''
758+
WHERE ocp.year = {{year}}
758759
AND lpad(ocp.month, 2, '0') = {{month}}
759760
AND ocp.usage_start >= {{start_date}}
760761
AND ocp.usage_start < date_add('day', 1, {{end_date}})
762+
AND aws.ocp_source = {{ocp_source_uuid}}
763+
AND aws.year = {{year}}
764+
AND aws.month = {{month}}
761765
GROUP BY ocp.persistentvolume, aws.resource_id
762766
) as combined_requests group by aws_resource_id
763767
)
@@ -802,7 +806,6 @@ JOIN hive.{{schema | sqlsafe}}.aws_openshift_daily_resource_matched_temp as aws
802806
JOIN hive.{{schema | sqlsafe}}.aws_openshift_disk_capacities_temp AS aws_disk
803807
ON aws_disk.usage_start = aws.usage_start
804808
AND aws_disk.resource_id = aws.resource_id
805-
AND aws_disk.ocp_source = {{ocp_source_uuid}}
806809
LEFT JOIN cte_total_pv_capacity as pv_cap
807810
ON pv_cap.aws_resource_id = aws.resource_id
808811
WHERE ocp.source = {{ocp_source_uuid}}
@@ -817,6 +820,9 @@ WHERE ocp.source = {{ocp_source_uuid}}
817820
AND aws.data_transfer_direction IS NULL
818821
AND ocp.namespace != 'Storage unattributed'
819822
AND aws_disk.capacity != pv_cap.total_pv_capacity -- prevent inserting zero cost rows
823+
AND aws_disk.year = {{year}}
824+
AND aws_disk.month = {{month}}
825+
AND aws_disk.ocp_source = {{ocp_source_uuid}}
820826
GROUP BY aws.uuid, aws.resource_id
821827
{% endif %}
822828
;
@@ -933,7 +939,9 @@ SELECT aws.uuid as aws_uuid,
933939
LEFT JOIN hive.{{schema | sqlsafe}}.aws_openshift_disk_capacities_temp AS aws_disk
934940
ON aws_disk.usage_start = aws.usage_start
935941
AND aws_disk.resource_id = aws.resource_id
936-
AND aws_disk.ocp_source = {{ocp_source_uuid}}
942+
AND aws_disk.year = aws.year
943+
AND aws_disk.month = aws.month
944+
AND aws_disk.ocp_source = aws.ocp_source
937945
WHERE ocp.source = {{ocp_source_uuid}}
938946
AND ocp.year = {{year}}
939947
AND lpad(ocp.month, 2, '0') = {{month}} -- Zero pad the month when fewer than 2 characters

koku/masu/database/trino_sql/reporting_ocpazurecostlineitem_daily_summary.sql

+13-7
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ SELECT cast(uuid() as varchar) as azure_uuid,
445445
JOIN hive.{{schema | sqlsafe}}.azure_openshift_disk_capacities_temp AS az_disk
446446
ON az_disk.usage_start = azure.usage_start
447447
AND az_disk.resource_id = azure.resource_id
448-
AND az_disk.ocp_source = {{ocp_source_uuid}}
449448
WHERE ocp.source = {{ocp_source_uuid}}
450449
AND ocp.year = {{year}}
451450
AND lpad(ocp.month, 2, '0') = {{month}} -- Zero pad the month when fewer than 2 characters
@@ -458,6 +457,9 @@ SELECT cast(uuid() as varchar) as azure_uuid,
458457
AND azure.year = {{year}}
459458
AND azure.month = {{month}}
460459
AND ocp.namespace != 'Storage unattributed'
460+
AND az_disk.year = {{year}}
461+
AND az_disk.month = {{month}}
462+
AND az_disk.ocp_source = {{ocp_source_uuid}}
461463
GROUP BY azure.uuid, ocp.namespace, ocp.data_source, ocp.pod_labels, ocp.volume_labels
462464
-- The endif needs to come before the ; when using sqlparse
463465
{% endif %}
@@ -508,11 +510,13 @@ WITH cte_total_pv_capacity as (
508510
OR
509511
(lower(ocp.csi_volume_handle) = lower(azure.resource_id))
510512
)
511-
WHERE ocp.source = {{ocp_source_uuid}}
512-
AND ocp.year = {{year}}
513+
WHERE ocp.year = {{year}}
513514
AND lpad(ocp.month, 2, '0') = {{month}}
514515
AND ocp.usage_start >= {{start_date}}
515516
AND ocp.usage_start < date_add('day', 1, {{end_date}})
517+
AND azure.ocp_source = {{ocp_source_uuid}}
518+
AND azure.year = {{year}}
519+
AND azure.month = {{month}}
516520
GROUP BY ocp.persistentvolume, azure.resource_id
517521
) as combined_requests group by azure_resource_id
518522
)
@@ -551,7 +555,6 @@ SELECT cast(uuid() as varchar) as azure_uuid, -- need a new uuid or it will dedu
551555
JOIN hive.{{schema | sqlsafe}}.azure_openshift_disk_capacities_temp AS az_disk
552556
ON az_disk.usage_start = azure.usage_start
553557
AND az_disk.resource_id = azure.resource_id
554-
AND az_disk.ocp_source = {{ocp_source_uuid}}
555558
LEFT JOIN cte_total_pv_capacity as pv_cap
556559
ON pv_cap.azure_resource_id = azure.resource_id
557560
WHERE ocp.source = {{ocp_source_uuid}}
@@ -563,6 +566,9 @@ SELECT cast(uuid() as varchar) as azure_uuid, -- need a new uuid or it will dedu
563566
AND azure.year = {{year}}
564567
AND azure.month = {{month}}
565568
AND ocp.namespace != 'Storage unattributed'
569+
AND az_disk.year = {{year}}
570+
AND az_disk.month = {{month}}
571+
AND az_disk.ocp_source = {{ocp_source_uuid}}
566572
GROUP BY azure.uuid, ocp.data_source, azure.resource_id
567573
{% endif %}
568574
;
@@ -665,9 +671,9 @@ SELECT azure.uuid as azure_uuid,
665671
)
666672
LEFT JOIN hive.{{schema | sqlsafe}}.azure_openshift_disk_capacities_temp as disk_cap
667673
ON azure.resource_id = disk_cap.resource_id
668-
AND azure.ocp_source = disk_cap.ocp_source
669-
AND azure.year = disk_cap.year
670-
AND azure.month = disk_cap.month
674+
AND disk_cap.year = azure.year
675+
AND disk_cap.month = azure.month
676+
AND disk_cap.ocp_source = azure.ocp_source
671677
WHERE ocp.source = {{ocp_source_uuid}}
672678
AND ocp.year = {{year}}
673679
AND lpad(ocp.month, 2, '0') = {{month}} -- Zero pad the month when fewer than 2 characters

0 commit comments

Comments
 (0)