Skip to content

Commit d575983

Browse files
select-expr-casting-support (#519)
Summary: - Basic support for cast functionality in select expressions. - Added robot test `AWS Materialized View and Cast and Multiple Function Query on Resource Costs Exemplifies Cast and Multiple Functions on Materialized Views`. - Cater for backend RDBMS precision differences.
1 parent 0e5d4fd commit d575983

File tree

7 files changed

+359
-9
lines changed

7 files changed

+359
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/stackql/any-sdk v0.0.5-beta01
2323
github.com/stackql/go-suffix-map v0.0.1-alpha01
2424
github.com/stackql/psql-wire v0.1.1-alpha07
25-
github.com/stackql/stackql-parser v0.0.14-alpha04
25+
github.com/stackql/stackql-parser v0.0.14-alpha05
2626
github.com/stretchr/testify v1.10.0
2727
golang.org/x/sync v0.10.0
2828
gonum.org/v1/gonum v0.11.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ github.com/stackql/readline v0.0.2-alpha05 h1:ID4QzGdplFBsrSnTuz8pvKzWw96JbrJg8f
492492
github.com/stackql/readline v0.0.2-alpha05/go.mod h1:OFAYOdXk/X4+5GYiDXFfaGrk+bCN6Qv0SYY5HNzD2E0=
493493
github.com/stackql/stackql-go-sqlite3 v1.0.3-stackql h1:j0yt6T5thZuz5+HIr81PXz2AClAtCko0vzr5tm8C1g8=
494494
github.com/stackql/stackql-go-sqlite3 v1.0.3-stackql/go.mod h1:HemqCrcMK2xyhMMMt6oZ7ERDtoSmyyDsw5LBBcTZ+Rk=
495-
github.com/stackql/stackql-parser v0.0.14-alpha04 h1:CmZUDWf2jBbU+Zu3sdiuM5CwUBFGN/IFjzXPcu46xjs=
496-
github.com/stackql/stackql-parser v0.0.14-alpha04/go.mod h1:iyB47SvRS+Fvpn7joF7mHAkeiWSq83TbUhglRmLzPLQ=
495+
github.com/stackql/stackql-parser v0.0.14-alpha05 h1:DLcsaeTypH5p1T+g/9NqaGYdC9uIQ+7pZetnkjHi0G0=
496+
github.com/stackql/stackql-parser v0.0.14-alpha05/go.mod h1:iyB47SvRS+Fvpn7joF7mHAkeiWSq83TbUhglRmLzPLQ=
497497
github.com/stackql/stackql-provider-registry v0.0.1-rc06 h1:MgroWOr0bSqjSTDGnXB0UoZGFXpW3SRtN0EFkzB8Rpo=
498498
github.com/stackql/stackql-provider-registry v0.0.1-rc06/go.mod h1:87rVxnS2aRASK20lBQgoYA0o7FSJTZBGGRaWFR7IDm4=
499499
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

internal/stackql/astvisit/query_rewriting.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,23 @@ func (v *standardQueryRewriteAstVisitor) Visit(node sqlparser.SQLNode) error {
684684
if col.Val != nil {
685685
relationalCol = typing.NewRelationalColumn(col.Name, v.getTypeFromParserType(col.Type)).WithDecorated(col.DecoratedColumn)
686686
} else {
687-
r, ok := indirect.GetColumnByName(col.Name)
688-
if !ok {
689-
if !v.isJSONEachCompatible(col) {
690-
return fmt.Errorf("query rewriting for indirection: cannot find col = '%s'", col.Name)
687+
_, isConvert := col.Expr.(*sqlparser.ConvertExpr)
688+
if isConvert {
689+
convertCol, convertColErr := parserutil.InferColNameFromExpr(node, v.formatter)
690+
if convertColErr != nil {
691+
return convertColErr
691692
}
692-
relationalCol = typing.NewRelationalColumn(col.Name, "").WithDecorated(col.DecoratedColumn) // TOOO: clean this up
693+
relationalCol = typing.NewRelationalColumn(convertCol.Name, v.getTypeFromParserType(col.Type)).WithDecorated(convertCol.DecoratedColumn)
693694
} else {
694-
relationalCol = typing.NewRelationalColumn(col.Name, r.GetType()).WithDecorated(col.DecoratedColumn)
695+
r, ok := indirect.GetColumnByName(col.Name)
696+
if !ok {
697+
if !v.isJSONEachCompatible(col) {
698+
return fmt.Errorf("query rewriting for indirection: cannot find col = '%s'", col.Name)
699+
}
700+
relationalCol = typing.NewRelationalColumn(col.Name, "").WithDecorated(col.DecoratedColumn) // TOOO: clean this up
701+
} else {
702+
relationalCol = typing.NewRelationalColumn(col.Name, r.GetType()).WithDecorated(col.DecoratedColumn)
703+
}
695704
}
696705
}
697706
}

internal/stackql/parserutil/parser_util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,15 @@ func inferColNameFromExpr(
622622
rv.DecoratedColumn = getDecoratedColRendition(decoratedColumn, alias)
623623
rv.Alias = alias
624624
return rv, nil
625+
default:
626+
decortedCol := astformat.String(node, formatter)
627+
rv := ColumnHandle{
628+
Alias: "",
629+
Expr: node,
630+
}
631+
rv.DecoratedColumn = getDecoratedColRendition(decortedCol, alias)
632+
rv.Alias = alias
633+
return rv, nil
625634
}
626635
case *sqlparser.SQLVal:
627636
// As a shortcut, functions are integral types
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
|------------|------------|--------------------------------|------------------------|------|
2+
| beginning | ending | keyz | amount | unit |
3+
|------------|------------|--------------------------------|------------------------|------|
4+
| 2024-11-01 | 2024-11-30 | ["AWS CloudFormation"] | 0 | USD |
5+
|------------|------------|--------------------------------|------------------------|------|
6+
| 2024-08-01 | 2024-09-01 | ["AWS Glue"] | 0 | USD |
7+
|------------|------------|--------------------------------|------------------------|------|
8+
| 2024-09-01 | 2024-10-01 | ["AWS Glue"] | 0 | USD |
9+
|------------|------------|--------------------------------|------------------------|------|
10+
| 2024-10-01 | 2024-11-01 | ["AWS Glue"] | 0 | USD |
11+
|------------|------------|--------------------------------|------------------------|------|
12+
| 2024-11-01 | 2024-11-30 | ["AWS Glue"] | 0 | USD |
13+
|------------|------------|--------------------------------|------------------------|------|
14+
| 2024-11-01 | 2024-11-30 | ["AWS Lambda"] | 0 | USD |
15+
|------------|------------|--------------------------------|------------------------|------|
16+
| 2024-08-01 | 2024-09-01 | ["AWS Secrets Manager"] | 0 | USD |
17+
|------------|------------|--------------------------------|------------------------|------|
18+
| 2024-09-01 | 2024-10-01 | ["AWS Secrets Manager"] | 0 | USD |
19+
|------------|------------|--------------------------------|------------------------|------|
20+
| 2024-10-01 | 2024-11-01 | ["AWS Secrets Manager"] | 0 | USD |
21+
|------------|------------|--------------------------------|------------------------|------|
22+
| 2024-11-01 | 2024-11-30 | ["AWS Secrets Manager"] | 0 | USD |
23+
|------------|------------|--------------------------------|------------------------|------|
24+
| 2024-08-01 | 2024-09-01 | ["Amazon Simple Notification | 0 | USD |
25+
| | | Service"] | | |
26+
|------------|------------|--------------------------------|------------------------|------|
27+
| 2024-09-01 | 2024-10-01 | ["Amazon Simple Notification | 0 | USD |
28+
| | | Service"] | | |
29+
|------------|------------|--------------------------------|------------------------|------|
30+
| 2024-10-01 | 2024-11-01 | ["Amazon Simple Notification | 0 | USD |
31+
| | | Service"] | | |
32+
|------------|------------|--------------------------------|------------------------|------|
33+
| 2024-11-01 | 2024-11-30 | ["Amazon Simple Notification | 0 | USD |
34+
| | | Service"] | | |
35+
|------------|------------|--------------------------------|------------------------|------|
36+
| 2024-08-01 | 2024-09-01 | ["Amazon Simple Queue | 0 | USD |
37+
| | | Service"] | | |
38+
|------------|------------|--------------------------------|------------------------|------|
39+
| 2024-09-01 | 2024-10-01 | ["Amazon Simple Queue | 0 | USD |
40+
| | | Service"] | | |
41+
|------------|------------|--------------------------------|------------------------|------|
42+
| 2024-10-01 | 2024-11-01 | ["Amazon Simple Queue | 0 | USD |
43+
| | | Service"] | | |
44+
|------------|------------|--------------------------------|------------------------|------|
45+
| 2024-11-01 | 2024-11-30 | ["Amazon Simple Queue | 0 | USD |
46+
| | | Service"] | | |
47+
|------------|------------|--------------------------------|------------------------|------|
48+
| 2024-08-01 | 2024-09-01 | ["AmazonCloudWatch"] | 0 | USD |
49+
|------------|------------|--------------------------------|------------------------|------|
50+
| 2024-09-01 | 2024-10-01 | ["AmazonCloudWatch"] | 0 | USD |
51+
|------------|------------|--------------------------------|------------------------|------|
52+
| 2024-10-01 | 2024-11-01 | ["AmazonCloudWatch"] | 0 | USD |
53+
|------------|------------|--------------------------------|------------------------|------|
54+
| 2024-11-01 | 2024-11-30 | ["AmazonCloudWatch"] | 0 | USD |
55+
|------------|------------|--------------------------------|------------------------|------|
56+
| 2024-11-01 | 2024-11-30 | ["AWS CloudShell"] | 2.1520000359487312e-07 | USD |
57+
|------------|------------|--------------------------------|------------------------|------|
58+
| 2024-11-01 | 2024-11-30 | ["Amazon Location Service"] | 0.0014550000196322799 | USD |
59+
|------------|------------|--------------------------------|------------------------|------|
60+
| 2024-09-01 | 2024-10-01 | ["Amazon Location Service"] | 0.0015539999585598707 | USD |
61+
|------------|------------|--------------------------------|------------------------|------|
62+
| 2024-08-01 | 2024-09-01 | ["Amazon Location Service"] | 0.0015839999541640282 | USD |
63+
|------------|------------|--------------------------------|------------------------|------|
64+
| 2024-10-01 | 2024-11-01 | ["Amazon Location Service"] | 0.0016530000139027834 | USD |
65+
|------------|------------|--------------------------------|------------------------|------|
66+
| 2024-08-01 | 2024-09-01 | ["Amazon DynamoDB"] | 0.0051069543696939945 | USD |
67+
|------------|------------|--------------------------------|------------------------|------|
68+
| 2024-08-01 | 2024-09-01 | ["Amazon Simple Storage | 0.04730991646647453 | USD |
69+
| | | Service"] | | |
70+
|------------|------------|--------------------------------|------------------------|------|
71+
| 2024-11-01 | 2024-11-30 | ["Amazon EC2 Container | 0.06115703284740448 | USD |
72+
| | | Registry (ECR)"] | | |
73+
|------------|------------|--------------------------------|------------------------|------|
74+
| 2024-08-01 | 2024-09-01 | ["Amazon EC2 Container | 0.06326588988304138 | USD |
75+
| | | Registry (ECR)"] | | |
76+
|------------|------------|--------------------------------|------------------------|------|
77+
| 2024-10-01 | 2024-11-01 | ["Amazon EC2 Container | 0.06326588988304138 | USD |
78+
| | | Registry (ECR)"] | | |
79+
|------------|------------|--------------------------------|------------------------|------|
80+
| 2024-09-01 | 2024-10-01 | ["Amazon EC2 Container | 0.06326589733362198 | USD |
81+
| | | Registry (ECR)"] | | |
82+
|------------|------------|--------------------------------|------------------------|------|
83+
| 2024-11-01 | 2024-11-30 | ["Amazon DynamoDB"] | 0.06669150292873383 | USD |
84+
|------------|------------|--------------------------------|------------------------|------|
85+
| 2024-09-01 | 2024-10-01 | ["Amazon DynamoDB"] | 0.0787472054362297 | USD |
86+
|------------|------------|--------------------------------|------------------------|------|
87+
| 2024-10-01 | 2024-11-01 | ["Amazon DynamoDB"] | 0.12785232067108154 | USD |
88+
|------------|------------|--------------------------------|------------------------|------|
89+
| 2024-09-01 | 2024-10-01 | ["Amazon Simple Storage | 0.35454288125038147 | USD |
90+
| | | Service"] | | |
91+
|------------|------------|--------------------------------|------------------------|------|
92+
| 2024-10-01 | 2024-11-01 | ["Amazon Simple Storage | 0.3908839821815491 | USD |
93+
| | | Service"] | | |
94+
|------------|------------|--------------------------------|------------------------|------|
95+
| 2024-11-01 | 2024-11-30 | ["Amazon Simple Storage | 0.6006374359130859 | USD |
96+
| | | Service"] | | |
97+
|------------|------------|--------------------------------|------------------------|------|
98+
| 2024-08-01 | 2024-09-01 | ["AWS Key Management Service"] | 1 | USD |
99+
|------------|------------|--------------------------------|------------------------|------|
100+
| 2024-11-01 | 2024-11-30 | ["AWS Config"] | 1.6790000200271606 | USD |
101+
|------------|------------|--------------------------------|------------------------|------|
102+
| 2024-09-01 | 2024-10-01 | ["AWS Config"] | 1.7589999437332153 | USD |
103+
|------------|------------|--------------------------------|------------------------|------|
104+
| 2024-10-01 | 2024-11-01 | ["AWS Config"] | 1.805999994277954 | USD |
105+
|------------|------------|--------------------------------|------------------------|------|
106+
| 2024-08-01 | 2024-09-01 | ["EC2 - Other"] | 1.832593321800232 | USD |
107+
|------------|------------|--------------------------------|------------------------|------|
108+
| 2024-08-01 | 2024-09-01 | ["AWS Config"] | 1.9819999933242798 | USD |
109+
|------------|------------|--------------------------------|------------------------|------|
110+
| 2024-10-01 | 2024-11-01 | ["EC2 - Other"] | 2.3042662143707275 | USD |
111+
|------------|------------|--------------------------------|------------------------|------|
112+
| 2024-09-01 | 2024-10-01 | ["EC2 - Other"] | 2.304311513900757 | USD |
113+
|------------|------------|--------------------------------|------------------------|------|
114+
| 2024-08-01 | 2024-09-01 | ["Tax"] | 3.4200000762939453 | USD |
115+
|------------|------------|--------------------------------|------------------------|------|
116+
| 2024-09-01 | 2024-10-01 | ["AWS Key Management Service"] | 4.1631550788879395 | USD |
117+
|------------|------------|--------------------------------|------------------------|------|
118+
| 2024-09-01 | 2024-10-01 | ["Tax"] | 4.579999923706055 | USD |
119+
|------------|------------|--------------------------------|------------------------|------|
120+
| 2024-10-01 | 2024-11-01 | ["Tax"] | 4.940000057220459 | USD |
121+
|------------|------------|--------------------------------|------------------------|------|
122+
| 2024-10-01 | 2024-11-01 | ["AWS Key Management Service"] | 6.3830108642578125 | USD |
123+
|------------|------------|--------------------------------|------------------------|------|
124+
| 2024-11-01 | 2024-11-30 | ["AWS Key Management Service"] | 6.405858516693115 | USD |
125+
|------------|------------|--------------------------------|------------------------|------|
126+
| 2024-08-01 | 2024-09-01 | ["Amazon Virtual Private | 8.857989311218262 | USD |
127+
| | | Cloud"] | | |
128+
|------------|------------|--------------------------------|------------------------|------|
129+
| 2024-09-01 | 2024-10-01 | ["Amazon Virtual Private | 10.800800323486328 | USD |
130+
| | | Cloud"] | | |
131+
|------------|------------|--------------------------------|------------------------|------|
132+
| 2024-10-01 | 2024-11-01 | ["Amazon Virtual Private | 11.15999984741211 | USD |
133+
| | | Cloud"] | | |
134+
|------------|------------|--------------------------------|------------------------|------|
135+
| 2024-11-01 | 2024-11-30 | ["Tax"] | 14.039999961853027 | USD |
136+
|------------|------------|--------------------------------|------------------------|------|
137+
| 2024-08-01 | 2024-09-01 | ["Amazon Elastic Compute Cloud | 20.445402145385742 | USD |
138+
| | | - Compute"] | | |
139+
|------------|------------|--------------------------------|------------------------|------|
140+
| 2024-09-01 | 2024-10-01 | ["Amazon Elastic Compute Cloud | 26.282133102416992 | USD |
141+
| | | - Compute"] | | |
142+
|------------|------------|--------------------------------|------------------------|------|
143+
| 2024-10-01 | 2024-11-01 | ["Amazon Elastic Compute Cloud | 27.126800537109375 | USD |
144+
| | | - Compute"] | | |
145+
|------------|------------|--------------------------------|------------------------|------|
146+
| 2024-11-01 | 2024-11-30 | ["Amazon Elastic Compute Cloud | 27.15462303161621 | USD |
147+
| | | - Compute"] | | |
148+
|------------|------------|--------------------------------|------------------------|------|
149+
| 2024-11-01 | 2024-11-30 | ["Amazon Virtual Private | 47.563499450683594 | USD |
150+
| | | Cloud"] | | |
151+
|------------|------------|--------------------------------|------------------------|------|
152+
| 2024-11-01 | 2024-11-30 | ["EC2 - Other"] | 50.93074035644531 | USD |
153+
|------------|------------|--------------------------------|------------------------|------|

0 commit comments

Comments
 (0)