From 8cbfd222ad49600002b4bd0c7db0d9716c975b8d Mon Sep 17 00:00:00 2001 From: Corey Goodfred Date: Mon, 24 Jun 2024 07:53:00 -0400 Subject: [PATCH] Filter accounts by matching criteria during subs processing to prevent unnecessary SQL from running (#5184) --- koku/subs/trino_sql/aws/determine_ids_for_provider.sql | 2 ++ koku/subs/trino_sql/azure/determine_ids_for_provider.sql | 3 +++ 2 files changed, 5 insertions(+) diff --git a/koku/subs/trino_sql/aws/determine_ids_for_provider.sql b/koku/subs/trino_sql/aws/determine_ids_for_provider.sql index 00fe502ae8..518975e111 100644 --- a/koku/subs/trino_sql/aws/determine_ids_for_provider.sql +++ b/koku/subs/trino_sql/aws/determine_ids_for_provider.sql @@ -3,6 +3,8 @@ FROM hive.{{schema | sqlsafe}}.aws_line_items WHERE source={{source_uuid}} AND year={{year}} AND month={{month}} + AND lineitem_productcode = 'AmazonEC2' + AND strpos(lower(resourcetags), 'com_redhat_rhel') > 0 {% if excluded_ids %} AND lineitem_usageaccountid NOT IN {{excluded_ids | inclause}} {% endif %} diff --git a/koku/subs/trino_sql/azure/determine_ids_for_provider.sql b/koku/subs/trino_sql/azure/determine_ids_for_provider.sql index e80bf13289..cea4912e39 100644 --- a/koku/subs/trino_sql/azure/determine_ids_for_provider.sql +++ b/koku/subs/trino_sql/azure/determine_ids_for_provider.sql @@ -3,6 +3,9 @@ FROM hive.{{schema | sqlsafe}}.azure_line_items WHERE source={{source_uuid}} AND year={{year}} AND month={{month}} + AND metercategory = 'Virtual Machines' + AND json_extract_scalar(lower(additionalinfo), '$.vcpus') IS NOT NULL + AND json_extract_scalar(lower(tags), '$.com_redhat_rhel') IS NOT NULL {% if excluded_ids %} AND COALESCE(NULLIF(subscriptionid, ''), subscriptionguid) NOT IN {{excluded_ids | inclause}} {% endif %}