-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[COST-5657] subs: use subquery in Trino to join from Postgres (#5381)
* join postgres table in trino sql
- Loading branch information
Showing
5 changed files
with
66 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
SELECT DISTINCT lineitem_usageaccountid | ||
SELECT | ||
DISTINCT lineitem_usageaccountid | ||
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 %} | ||
AND lineitem_usageaccountid NOT IN ( | ||
SELECT | ||
DISTINCT usage_id | ||
FROM postgres.{{schema | sqlsafe}}.reporting_subs_id_map | ||
WHERE source_uuid!=cast({{source_uuid}} as uuid) | ||
) |
25 changes: 16 additions & 9 deletions
25
koku/subs/trino_sql/aws/determine_resource_ids_for_usage_account.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
SELECT lineitem_resourceid, max(lineitem_usagestartdate) | ||
SELECT | ||
lineitem_resourceid, | ||
max(lineitem_usagestartdate) | ||
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 | ||
AND lineitem_usageaccountid = {{usage_account}} | ||
{% if excluded_ids %} | ||
AND lineitem_resourceid NOT IN {{excluded_ids | inclause}} | ||
{% endif %} | ||
AND year={{year}} | ||
AND month={{month}} | ||
AND lineitem_productcode = 'AmazonEC2' | ||
AND strpos(lower(resourcetags), 'com_redhat_rhel') > 0 | ||
AND lineitem_usageaccountid = {{usage_account}} | ||
AND lineitem_resourceid NOT IN ( | ||
SELECT | ||
DISTINCT resource_id | ||
FROM postgres.{{schema | sqlsafe}}.reporting_subs_last_processed_time | ||
WHERE source_uuid != cast({{source_uuid}} as uuid) | ||
AND year={{year}} | ||
AND month={{month}} | ||
) | ||
GROUP BY lineitem_resourceid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
SELECT DISTINCT COALESCE(NULLIF(subscriptionid, ''), subscriptionguid) | ||
SELECT | ||
DISTINCT COALESCE(NULLIF(subscriptionid, ''), subscriptionguid) | ||
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 %} | ||
AND COALESCE(NULLIF(subscriptionid, ''), subscriptionguid) NOT IN ( | ||
SELECT | ||
DISTINCT usage_id | ||
FROM postgres.{{schema | sqlsafe}}.reporting_subs_id_map | ||
WHERE source_uuid!=cast({{source_uuid}} as uuid) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters