@@ -21,18 +21,6 @@ use sqlparser::dialect::{BigQueryDialect, GenericDialect};
21
21
use sqlparser:: parser:: ParserError ;
22
22
use test_utils:: * ;
23
23
24
- /// Strips out newlines and spaces from the `sql` so that it can
25
- /// be comparable with the serialized result
26
- fn trim_sql ( sql : & str ) -> String {
27
- sql. split ( '\n' )
28
- . filter ( |line| !line. trim ( ) . is_empty ( ) )
29
- . map ( |line| line. trim_start ( ) )
30
- . collect :: < Vec < _ > > ( )
31
- . join ( " " )
32
- . trim ( )
33
- . to_string ( )
34
- }
35
-
36
24
#[ test]
37
25
fn parse_literal_string ( ) {
38
26
let sql = r#"SELECT 'single', "double""# ;
@@ -100,18 +88,14 @@ fn parse_raw_literal() {
100
88
101
89
#[ test]
102
90
fn parse_create_view_with_options ( ) {
103
- let sql = trim_sql (
104
- r#"
105
- CREATE VIEW myproject.mydataset.newview
106
- (name, age OPTIONS (description = "field age"))
107
- OPTIONS
108
- (expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR),
109
- friendly_name = "newview",
110
- description = "a view that expires in 2 days",
111
- labels = [("org_unit", "development")])
112
- AS SELECT column_1, column_2, column_3 FROM myproject.mydataset.mytable"# ,
91
+ let sql = concat ! (
92
+ "CREATE VIEW myproject.mydataset.newview " ,
93
+ r#"(name, age OPTIONS(description = "field age")) "# ,
94
+ r#"OPTIONS(expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR), "# ,
95
+ r#"friendly_name = "newview", description = "a view that expires in 2 days", labels = [("org_unit", "development")]) "# ,
96
+ "AS SELECT column_1, column_2, column_3 FROM myproject.mydataset.mytable" ,
113
97
) ;
114
- match bigquery ( ) . verified_stmt ( sql. as_str ( ) ) {
98
+ match bigquery ( ) . verified_stmt ( sql) {
115
99
Statement :: CreateView {
116
100
name,
117
101
query,
@@ -148,7 +132,7 @@ fn parse_create_view_with_options() {
148
132
query. to_string( )
149
133
) ;
150
134
assert_eq ! (
151
- r#"OPTIONS (expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR), friendly_name = "newview", description = "a view that expires in 2 days", labels = [("org_unit", "development")])"# ,
135
+ r#"OPTIONS(expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 48 HOUR), friendly_name = "newview", description = "a view that expires in 2 days", labels = [("org_unit", "development")])"# ,
152
136
options. to_string( )
153
137
) ;
154
138
let CreateTableOptions :: Options ( options) = options else {
@@ -170,19 +154,15 @@ fn parse_create_view_with_options() {
170
154
171
155
#[ test]
172
156
fn parse_create_table_with_options ( ) {
173
- let sql = trim_sql (
174
- r#"
175
- CREATE TABLE mydataset.newtable
176
- (x INT64 NOT NULL OPTIONS (description = "field x"),
177
- y BOOL OPTIONS (description = "field y"))
178
-
179
- PARTITION BY _PARTITIONDATE
180
- CLUSTER BY userid, age
181
- OPTIONS(partition_expiration_days = 1,
182
- description = "table option description")
183
- "# ,
157
+ let sql = concat ! (
158
+ "CREATE TABLE mydataset.newtable " ,
159
+ r#"(x INT64 NOT NULL OPTIONS(description = "field x"), "# ,
160
+ r#"y BOOL OPTIONS(description = "field y")) "# ,
161
+ "PARTITION BY _PARTITIONDATE " ,
162
+ "CLUSTER BY userid, age " ,
163
+ r#"OPTIONS(partition_expiration_days = 1, description = "table option description")"#
184
164
) ;
185
- match bigquery ( ) . verified_stmt ( sql. as_str ( ) ) {
165
+ match bigquery ( ) . verified_stmt ( sql) {
186
166
Statement :: CreateTable {
187
167
name,
188
168
columns,
@@ -255,18 +235,15 @@ fn parse_create_table_with_options() {
255
235
_ => unreachable ! ( ) ,
256
236
}
257
237
258
- let sql = trim_sql (
259
- r#"
260
- CREATE TABLE mydataset.newtable
261
- (x INT64 NOT NULL OPTIONS (description = "field x"),
262
- y BOOL OPTIONS (description = "field y"))
263
-
264
- CLUSTER BY userid
265
- OPTIONS(partition_expiration_days = 1,
266
- description = "table option description")
267
- "# ,
238
+ let sql = concat ! (
239
+ "CREATE TABLE mydataset.newtable " ,
240
+ r#"(x INT64 NOT NULL OPTIONS(description = "field x"), "# ,
241
+ r#"y BOOL OPTIONS(description = "field y")) "# ,
242
+ "CLUSTER BY userid " ,
243
+ r#"OPTIONS(partition_expiration_days = 1, "# ,
244
+ r#"description = "table option description")"#
268
245
) ;
269
- bigquery ( ) . verified_stmt ( sql. as_str ( ) ) ;
246
+ bigquery ( ) . verified_stmt ( sql) ;
270
247
}
271
248
272
249
#[ test]
0 commit comments