@@ -6,6 +6,29 @@ import (
6
6
"testing"
7
7
)
8
8
9
+ var simplePostOpsBlock = `
10
+ post_operations {
11
+ select 1
12
+ union all
13
+ select 2
14
+ }
15
+ `
16
+
17
+ var complexPreOpsBlock = `
18
+ pre_operations {
19
+ ${when(incremental(),` +
20
+ "`" + `
21
+ DELETE
22
+ FROM
23
+ ${self()}
24
+ WHERE
25
+ DATE(SNAPSHOT_DATE) = CURRENT_DATE()` +
26
+ "`" + `
27
+ )
28
+ }
29
+ }
30
+ `
31
+
9
32
func TestSqlxParser (t * testing.T ) {
10
33
tests := []struct {
11
34
name string
@@ -69,18 +92,12 @@ config {
69
92
clusterBy: ["CITY", "STATE"]
70
93
},
71
94
tags: ["TAG_1"]
72
- }
73
- pre_operations {
74
- ${when(incremental(), ` + "`" + `DELETE
75
- FROM
76
- ${self()}
77
- WHERE
78
- DATE(PIPELINE_RUN_DATETIME) = CURRENT_DATE()` + "`" + `)}
79
- }
80
-
81
- SELECT * FROM electric_cars WHERE model = $1;` ,
95
+ }` + complexPreOpsBlock + simplePostOpsBlock + `
96
+ SELECT * FROM electric_cars WHERE model = $1
97
+ limit 100
98
+ ` ,
82
99
expected : sqlxParserMeta {
83
- numLines : 21 ,
100
+ numLines : 32 ,
84
101
configBlockMeta : ConfigBlockMeta {
85
102
exsists : true ,
86
103
startOfConfigBlock : 2 ,
@@ -99,24 +116,28 @@ config {
99
116
}` ,
100
117
},
101
118
sqlBlocksMeta : SqlBlockMeta {
102
- exsists : true ,
103
- startOfSqlBlock : 21 ,
104
- endOfSqlBlock : 21 ,
105
- sqlBlockContent : `SELECT * FROM electric_cars WHERE model = $1;` ,
119
+ exsists : true ,
120
+ startOfSqlBlock : 30 ,
121
+ endOfSqlBlock : 32 ,
122
+ sqlBlockContent : `SELECT * FROM electric_cars WHERE model = $1
123
+ limit 100
124
+ ` ,
106
125
formattedSqlBlockContent : "" ,
107
126
},
108
127
preOpsBlocksMeta : []PreOpsBlockMeta {
109
128
{
110
129
exsists : true ,
111
130
startOfPreOperationsBlock : 13 ,
112
- endOfPreOperationsBlock : 19 ,
113
- preOpsBlockContent : `pre_operations {
114
- ${when(incremental(), ` + "`" + `DELETE
115
- FROM
116
- ${self()}
117
- WHERE
118
- DATE(PIPELINE_RUN_DATETIME) = CURRENT_DATE()` + "`" + `)}
119
- }` ,
131
+ endOfPreOperationsBlock : 22 ,
132
+ preOpsBlockContent : strings .TrimPrefix (complexPreOpsBlock , "\n " ),
133
+ },
134
+ },
135
+ postOpsBlocksMeta : []PostOpsBlockMeta {
136
+ {
137
+ exsists : true ,
138
+ startOfpostOperationsBlock : 24 ,
139
+ endOfpostOperationsBlock : 28 ,
140
+ postOpsBlockContent : strings .TrimPrefix (simplePostOpsBlock , "\n " ),
120
141
},
121
142
},
122
143
},
@@ -180,15 +201,34 @@ config {
180
201
t .Errorf ("[got]: endOfSqlBlock = %v, [want]: %v" , got .sqlBlocksMeta .endOfSqlBlock , tt .expected .sqlBlocksMeta .endOfSqlBlock )
181
202
}
182
203
183
- if len (tt .expected .preOpsBlocksMeta ) > 0 {
184
- if got .preOpsBlocksMeta [0 ].startOfPreOperationsBlock != tt .expected .preOpsBlocksMeta [0 ].startOfPreOperationsBlock {
185
- t .Errorf ("[got]: startOfPreOperationsBlock = %v, [want]: %v" , got .preOpsBlocksMeta [0 ].startOfPreOperationsBlock , tt .expected .preOpsBlocksMeta [0 ].startOfPreOperationsBlock )
186
- }
204
+ if len (tt .expected .preOpsBlocksMeta ) > 0 || len (tt .expected .preOpsBlocksMeta ) > 0 {
187
205
188
- if got .preOpsBlocksMeta [0 ].endOfPreOperationsBlock != tt .expected .preOpsBlocksMeta [0 ].endOfPreOperationsBlock {
189
- t .Errorf ("[got]: endOfPreOperationsBlock = %v, [want]: %v" , got .preOpsBlocksMeta [0 ].endOfPreOperationsBlock , tt .expected .preOpsBlocksMeta [0 ].endOfPreOperationsBlock )
190
- }
191
- }
206
+ if got .preOpsBlocksMeta [0 ].startOfPreOperationsBlock != tt .expected .preOpsBlocksMeta [0 ].startOfPreOperationsBlock {
207
+ t .Errorf ("[got]: startOfPreOperationsBlock = %v, [want]: %v" , got .preOpsBlocksMeta [0 ].startOfPreOperationsBlock , tt .expected .preOpsBlocksMeta [0 ].startOfPreOperationsBlock )
208
+ }
209
+
210
+ if got .preOpsBlocksMeta [0 ].endOfPreOperationsBlock != tt .expected .preOpsBlocksMeta [0 ].endOfPreOperationsBlock {
211
+ t .Errorf ("[got]: endOfPreOperationsBlock = %v, [want]: %v" , got .preOpsBlocksMeta [0 ].endOfPreOperationsBlock , tt .expected .preOpsBlocksMeta [0 ].endOfPreOperationsBlock )
212
+ }
213
+
214
+ if got .preOpsBlocksMeta [0 ].preOpsBlockContent != tt .expected .preOpsBlocksMeta [0 ].preOpsBlockContent {
215
+ t .Errorf ("[got]: preOpsBlockContent = %q, [want]: %q" , got .preOpsBlocksMeta [0 ].preOpsBlockContent , tt .expected .preOpsBlocksMeta [0 ].preOpsBlockContent )
216
+ }
217
+
218
+ }
219
+
220
+ if len (tt .expected .postOpsBlocksMeta ) > 0 || len (tt .expected .postOpsBlocksMeta ) > 0 {
221
+ if got .postOpsBlocksMeta [0 ].startOfpostOperationsBlock != tt .expected .postOpsBlocksMeta [0 ].startOfpostOperationsBlock {
222
+ t .Errorf ("[got]: startOfpostOperationsBlock = %v, [want]: %v" , got .postOpsBlocksMeta [0 ].startOfpostOperationsBlock , tt .expected .postOpsBlocksMeta [0 ].startOfpostOperationsBlock )
223
+ }
224
+
225
+ if got .postOpsBlocksMeta [0 ].endOfpostOperationsBlock != tt .expected .postOpsBlocksMeta [0 ].endOfpostOperationsBlock {
226
+ t .Errorf ("[got]: endOfpostOperationsBlock = %v, [want]: %v" , got .postOpsBlocksMeta [0 ].endOfpostOperationsBlock , tt .expected .postOpsBlocksMeta [0 ].endOfpostOperationsBlock )
227
+ }
228
+ if got .postOpsBlocksMeta [0 ].postOpsBlockContent != tt .expected .postOpsBlocksMeta [0 ].postOpsBlockContent {
229
+ t .Errorf ("[got]: postOpsBlockContent = %q, [want]: %q" , got .postOpsBlocksMeta [0 ].postOpsBlockContent , tt .expected .postOpsBlocksMeta [0 ].postOpsBlockContent )
230
+ }
231
+ }
192
232
193
233
})
194
234
}
0 commit comments