Skip to content

Commit dfe9169

Browse files
indirect-column-routing
Summary: - Support for nexted functions on indirecto columns. - Added robot test `AWS Materialized View And Multiple Function Query on Resource Costs Exemplifies Multiple Functions on Materialized Views`.
1 parent 87e57d9 commit dfe9169

File tree

3 files changed

+181
-2
lines changed

3 files changed

+181
-2
lines changed

internal/stackql/astvisit/query_rewriting.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import (
2525
)
2626

2727
var (
28-
_ QueryRewriteAstVisitor = &standardQueryRewriteAstVisitor{}
29-
isJSONEachCompatibleRegexp *regexp.Regexp = regexp.MustCompile(`^.*\.value$`) //nolint:revive // acceptable
28+
_ QueryRewriteAstVisitor = &standardQueryRewriteAstVisitor{}
29+
//nolint:revive // acceptable
30+
isJSONEachCompatibleRegexp *regexp.Regexp = regexp.MustCompile(
31+
`^(.*\.value|value)$`)
3032
)
3133

3234
type QueryRewriteAstVisitor interface {
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
|--------------------------------|---------------|------|
2+
| keys | amount | unit |
3+
|--------------------------------|---------------|------|
4+
| ["AWS Glue"] | 0 | USD |
5+
|--------------------------------|---------------|------|
6+
| ["AWS Secrets Manager"] | 0 | USD |
7+
|--------------------------------|---------------|------|
8+
| ["Amazon Simple Notification | 0 | USD |
9+
| Service"] | | |
10+
|--------------------------------|---------------|------|
11+
| ["Amazon Simple Queue | 0 | USD |
12+
| Service"] | | |
13+
|--------------------------------|---------------|------|
14+
| ["AmazonCloudWatch"] | 0 | USD |
15+
|--------------------------------|---------------|------|
16+
| ["AWS Glue"] | 0 | USD |
17+
|--------------------------------|---------------|------|
18+
| ["AWS Secrets Manager"] | 0 | USD |
19+
|--------------------------------|---------------|------|
20+
| ["Amazon Simple Notification | 0 | USD |
21+
| Service"] | | |
22+
|--------------------------------|---------------|------|
23+
| ["Amazon Simple Queue | 0 | USD |
24+
| Service"] | | |
25+
|--------------------------------|---------------|------|
26+
| ["AmazonCloudWatch"] | 0 | USD |
27+
|--------------------------------|---------------|------|
28+
| ["AWS Glue"] | 0 | USD |
29+
|--------------------------------|---------------|------|
30+
| ["AWS Secrets Manager"] | 0 | USD |
31+
|--------------------------------|---------------|------|
32+
| ["Amazon Simple Notification | 0 | USD |
33+
| Service"] | | |
34+
|--------------------------------|---------------|------|
35+
| ["Amazon Simple Queue | 0 | USD |
36+
| Service"] | | |
37+
|--------------------------------|---------------|------|
38+
| ["AmazonCloudWatch"] | 0 | USD |
39+
|--------------------------------|---------------|------|
40+
| ["AWS CloudFormation"] | 0 | USD |
41+
|--------------------------------|---------------|------|
42+
| ["AWS Glue"] | 0 | USD |
43+
|--------------------------------|---------------|------|
44+
| ["AWS Lambda"] | 0 | USD |
45+
|--------------------------------|---------------|------|
46+
| ["AWS Secrets Manager"] | 0 | USD |
47+
|--------------------------------|---------------|------|
48+
| ["Amazon Simple Notification | 0 | USD |
49+
| Service"] | | |
50+
|--------------------------------|---------------|------|
51+
| ["Amazon Simple Queue | 0 | USD |
52+
| Service"] | | |
53+
|--------------------------------|---------------|------|
54+
| ["AmazonCloudWatch"] | 0 | USD |
55+
|--------------------------------|---------------|------|
56+
| ["AWS CloudShell"] | 0.0000002152 | USD |
57+
|--------------------------------|---------------|------|
58+
| ["Amazon Location Service"] | 0.001455 | USD |
59+
|--------------------------------|---------------|------|
60+
| ["Amazon Location Service"] | 0.001554 | USD |
61+
|--------------------------------|---------------|------|
62+
| ["Amazon Location Service"] | 0.001584 | USD |
63+
|--------------------------------|---------------|------|
64+
| ["Amazon Location Service"] | 0.001653 | USD |
65+
|--------------------------------|---------------|------|
66+
| ["Amazon DynamoDB"] | 0.0051069546 | USD |
67+
|--------------------------------|---------------|------|
68+
| ["Amazon Simple Storage | 0.0473099157 | USD |
69+
| Service"] | | |
70+
|--------------------------------|---------------|------|
71+
| ["Amazon EC2 Container | 0.0611570328 | USD |
72+
| Registry (ECR)"] | | |
73+
|--------------------------------|---------------|------|
74+
| ["Amazon EC2 Container | 0.0632658912 | USD |
75+
| Registry (ECR)"] | | |
76+
|--------------------------------|---------------|------|
77+
| ["Amazon EC2 Container | 0.0632658912 | USD |
78+
| Registry (ECR)"] | | |
79+
|--------------------------------|---------------|------|
80+
| ["Amazon EC2 Container | 0.063265896 | USD |
81+
| Registry (ECR)"] | | |
82+
|--------------------------------|---------------|------|
83+
| ["Amazon DynamoDB"] | 0.066691505 | USD |
84+
|--------------------------------|---------------|------|
85+
| ["Amazon DynamoDB"] | 0.0787472044 | USD |
86+
|--------------------------------|---------------|------|
87+
| ["Amazon DynamoDB"] | 0.1278523226 | USD |
88+
|--------------------------------|---------------|------|
89+
| ["Amazon Simple Storage | 0.3545428953 | USD |
90+
| Service"] | | |
91+
|--------------------------------|---------------|------|
92+
| ["Amazon Simple Storage | 0.3908839969 | USD |
93+
| Service"] | | |
94+
|--------------------------------|---------------|------|
95+
| ["Amazon Simple Storage | 0.6006374463 | USD |
96+
| Service"] | | |
97+
|--------------------------------|---------------|------|
98+
| ["AWS Key Management Service"] | 0.999999984 | USD |
99+
|--------------------------------|---------------|------|
100+
| ["AWS Config"] | 1.679 | USD |
101+
|--------------------------------|---------------|------|
102+
| ["AWS Config"] | 1.759 | USD |
103+
|--------------------------------|---------------|------|
104+
| ["AWS Config"] | 1.806 | USD |
105+
|--------------------------------|---------------|------|
106+
| ["EC2 - Other"] | 1.8325932937 | USD |
107+
|--------------------------------|---------------|------|
108+
| ["AWS Config"] | 1.982 | USD |
109+
|--------------------------------|---------------|------|
110+
| ["Amazon Virtual Private | 10.8008 | USD |
111+
| Cloud"] | | |
112+
|--------------------------------|---------------|------|
113+
| ["Amazon Virtual Private | 11.16 | USD |
114+
| Cloud"] | | |
115+
|--------------------------------|---------------|------|
116+
| ["Tax"] | 14.04 | USD |
117+
|--------------------------------|---------------|------|
118+
| ["EC2 - Other"] | 2.3042661799 | USD |
119+
|--------------------------------|---------------|------|
120+
| ["EC2 - Other"] | 2.3043115302 | USD |
121+
|--------------------------------|---------------|------|
122+
| ["Amazon Elastic Compute Cloud | 20.445402 | USD |
123+
| - Compute"] | | |
124+
|--------------------------------|---------------|------|
125+
| ["Amazon Elastic Compute Cloud | 26.2821332206 | USD |
126+
| - Compute"] | | |
127+
|--------------------------------|---------------|------|
128+
| ["Amazon Elastic Compute Cloud | 27.1268 | USD |
129+
| - Compute"] | | |
130+
|--------------------------------|---------------|------|
131+
| ["Amazon Elastic Compute Cloud | 27.1546234373 | USD |
132+
| - Compute"] | | |
133+
|--------------------------------|---------------|------|
134+
| ["Tax"] | 3.42 | USD |
135+
|--------------------------------|---------------|------|
136+
| ["AWS Key Management Service"] | 4.163155008 | USD |
137+
|--------------------------------|---------------|------|
138+
| ["Tax"] | 4.58 | USD |
139+
|--------------------------------|---------------|------|
140+
| ["Tax"] | 4.94 | USD |
141+
|--------------------------------|---------------|------|
142+
| ["Amazon Virtual Private | 47.5634987792 | USD |
143+
| Cloud"] | | |
144+
|--------------------------------|---------------|------|
145+
| ["EC2 - Other"] | 50.9307417991 | USD |
146+
|--------------------------------|---------------|------|
147+
| ["AWS Key Management Service"] | 6.383010812 | USD |
148+
|--------------------------------|---------------|------|
149+
| ["AWS Key Management Service"] | 6.4058586744 | USD |
150+
|--------------------------------|---------------|------|
151+
| ["Amazon Virtual Private | 8.857988885 | USD |
152+
| Cloud"] | | |
153+
|--------------------------------|---------------|------|

test/robot/functional/stackql_mocked_from_cmd_line.robot

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7496,3 +7496,27 @@ AWS Materialized View And Query on Resource Costs Exemplifies Functions On Mater
74967496
... DDL Execution Completed
74977497
... stdout=${CURDIR}/tmp/AWS-Materialized-View-And-Query-on-Resource-Costs-Exemplifies-Functions-On-Materialized-Views.tmp
74987498
... stderr=${CURDIR}/tmp/AWS-Materialized-View-And-Query-on-Resource-Costs-Exemplifies-Functions-On-Materialized-Views-stderr.tmp
7499+
7500+
AWS Materialized View And Multiple Function Query on Resource Costs Exemplifies Multiple Functions on Materialized Views
7501+
[Tags] registry tls_proxied
7502+
${sqliteInputStr} = Catenate
7503+
... create or replace materialized view e1 as select json_extract(json_each.value, '$.Groups') as rez from aws.ce_native.cost_and_usage, json_each(ResultsByTime) where data__Granularity = 'MONTHLY' and data__Metrics = '["UnblendedCost"]' and data__TimePeriod = '{"Start": "2024-08-01", "End": "2024-11-30"}' and data__GroupBy = '[{"Type":"DIMENSION","Key":"SERVICE"}]' and region = 'us-east-1';
7504+
... select json_extract(json_each.value, '$.Keys') as keys, json_extract(json_each.value, '$.Metrics.UnblendedCost.Amount') as amount, json_extract(json_each.value, '$.Metrics.UnblendedCost.Unit') as unit from e1, json_each(e1.rez) order by amount;
7505+
${postgresInputStr} = Catenate
7506+
... create or replace materialized view e1 as select json_extract_path_text(rd.value, 'Groups') as rez from aws.ce_native.cost_and_usage, json_array_elements_text(ResultsByTime) as rd where data__Granularity = 'MONTHLY' and data__Metrics = '["UnblendedCost"]' and data__TimePeriod = '{"Start": "2024-08-01", "End": "2024-11-30"}' and data__GroupBy = '[{"Type":"DIMENSION","Key":"SERVICE"}]' and region = 'us-east-1';
7507+
... select json_extract_path_text(rd.value, '$.Keys') as keys, json_extract_path_text(rd.value, '$.Metrics.UnblendedCost.Amount') as amount, json_extract_path_text(rd.value, '$.Metrics.UnblendedCost.Unit') as unit from e1, json_array_elements_text(e1.rez) as rd order by amount;
7508+
${inputStr} = Set Variable If "${SQL_BACKEND}" == "postgres_tcp" ${postgresInputStr} ${sqliteInputStr}
7509+
${outputStr} = Get File ${REPOSITORY_ROOT}${/}test${/}assets${/}expected${/}aws${/}ce${/}ce-nested-function-materialized-view.txt
7510+
Should Stackql Exec Inline Equal Both Streams
7511+
... ${STACKQL_EXE}
7512+
... ${OKTA_SECRET_STR}
7513+
... ${GITHUB_SECRET_STR}
7514+
... ${K8S_SECRET_STR}
7515+
... ${REGISTRY_NO_VERIFY_CFG_STR}
7516+
... ${AUTH_CFG_STR}
7517+
... ${SQL_BACKEND_CFG_STR_CANONICAL}
7518+
... ${inputStr}
7519+
... ${outputStr}
7520+
... DDL Execution Completed
7521+
... stdout=${CURDIR}/tmp/AWS-Materialized-View-And-Multiple-Function-Query-on-Resource-Costs-Exemplifies-Multiple-Functions-on-Materialized-Views.tmp
7522+
... stderr=${CURDIR}/tmp/AWS-Materialized-View-And-Multiple-Function-Query-on-Resource-Costs-Exemplifies-Multiple-Functions-on-Materialized-Views-stderr.tmp

0 commit comments

Comments
 (0)