-
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.
Factor sql maps into files and build less SQL in python
- Loading branch information
Showing
8 changed files
with
132 additions
and
80 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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SELECT | ||
DISTINCT lineitem_usageaccountid | ||
FROM | ||
hive.{{schema | sqlsafe}}.aws_line_items | ||
WHERE | ||
source = {{source_uuid}} | ||
AND year = {{year}} | ||
AND month = {{month}} | ||
{ % if excluded_ids % } | ||
AND lineitem_usageaccountid NOT IN {{excluded_ids | inclause}} | ||
{ % endif % } |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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 % } | ||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WHERE | ||
source = {{source_uuid}} | ||
AND year = {{year}} | ||
AND month = {{month}} | ||
AND lineitem_productcode = 'AmazonEC2' | ||
AND lineitem_lineitemtype IN ( | ||
'Usage', 'SavingsPlanCoveredUsage' | ||
) | ||
AND product_vcpu != '' | ||
AND strpos( | ||
lower(resourcetags), | ||
'com_redhat_rhel' | ||
) > 0 |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
SELECT | ||
DISTINCT COALESCE( | ||
NULLIF(subscriptionid, ''), | ||
subscriptionguid | ||
) | ||
FROM | ||
hive.{{schema | sqlsafe}}.azure_line_items | ||
WHERE | ||
source = {{source_uuid}} | ||
AND year = {{year}} | ||
AND month = {{month}} | ||
{ % if excluded_ids % } | ||
AND COALESCE( | ||
NULLIF(subscriptionid, ''), | ||
subscriptionguid | ||
) NOT IN {{excluded_ids | inclause}} | ||
{ % endif % } |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
SELECT | ||
coalesce( | ||
NULLIF(resourceid, ''), | ||
instancename | ||
), | ||
date_add( | ||
'day', | ||
-1, | ||
max( | ||
coalesce(date, usagedatetime) | ||
) | ||
) | ||
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 | ||
AND ( | ||
subscriptionid = {{usage_account}} | ||
or subscriptionguid = {{usage_account}} | ||
) | ||
{ % if excluded_ids % } | ||
AND coalesce( | ||
NULLIF(resourceid, ''), | ||
instancename | ||
) NOT IN {{excluded_ids | inclause}} | ||
{ % endif % } | ||
GROUP BY | ||
resourceid, | ||
instancename |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
WHERE | ||
source = {{source_uuid}} | ||
AND year = {{year}} | ||
AND month = {{month}} | ||
AND metercategory = 'Virtual Machines' | ||
AND chargetype = 'Usage' | ||
AND json_extract_scalar( | ||
lower(additionalinfo), | ||
'$.vcpus' | ||
) IS NOT NULL | ||
AND json_extract_scalar( | ||
lower(tags), | ||
'$.com_redhat_rhel' | ||
) IS NOT NULL |