@@ -191,148 +191,177 @@ impl<'a> SelectFromParser for Parser<'a> {
191
191
}
192
192
}
193
193
194
- // #[cfg(test)]
195
- // mod test_select_from_table_indexed {
196
- // use super::test_utils::select_from;
197
- // use crate::parser::test_utils::*;
198
- // use crate::{FromClause, Identifier, IndexedType, QualifiedTableName, Statement};
199
-
200
- // #[test]
201
- // fn test_select_from_table() {
202
- // let expected_statement = select_from(FromClause::Table(QualifiedTableName::from(
203
- // Identifier::Single("table_1".to_string()),
204
- // )));
205
-
206
- // run_sunny_day_test(
207
- // "SELECT * FROM table_1",
208
- // Statement::Select(expected_statement),
209
- // );
210
- // }
211
-
212
- // #[test]
213
- // fn test_select_from_table_with_schema() {
214
- // let expected_statement = select_from(FromClause::Table(QualifiedTableName::from(
215
- // Identifier::Compound(vec!["schema_1".to_string(), "table_1".to_string()]),
216
- // )));
217
-
218
- // run_sunny_day_test(
219
- // "SELECT * FROM schema_1.table_1",
220
- // Statement::Select(expected_statement),
221
- // );
222
- // }
223
-
224
- // #[test]
225
- // fn test_select_from_table_with_alias() {
226
- // let expected_statement = select_from(FromClause::Table(QualifiedTableName {
227
- // table_id: Identifier::Compound(vec!["schema_1".to_string(), "table_1".to_string()]),
228
- // alias: Some("alias".to_string()),
229
- // indexed_type: None,
230
- // }));
231
-
232
- // run_sunny_day_test(
233
- // "SELECT * FROM schema_1.table_1 AS alias",
234
- // Statement::Select(expected_statement),
235
- // );
236
- // }
237
-
238
- // #[test]
239
- // fn test_select_from_table_with_alias_without_as_keyword() {
240
- // let expected_statement = select_from(FromClause::Table(QualifiedTableName {
241
- // table_id: Identifier::Single("table_1".to_string()),
242
- // alias: Some("alias".to_string()),
243
- // indexed_type: None,
244
- // }));
245
-
246
- // run_sunny_day_test(
247
- // "SELECT * FROM table_1 alias",
248
- // Statement::Select(expected_statement),
249
- // );
250
- // }
251
-
252
- // #[test]
253
- // fn test_select_from_table_with_alias_indexed() {
254
- // let expected_statement = select_from(FromClause::Table(QualifiedTableName {
255
- // table_id: Identifier::Single("table_1".to_string()),
256
- // alias: Some("alias".to_string()),
257
- // indexed_type: Some(IndexedType::Indexed("index_1".to_string())),
258
- // }));
194
+ #[ cfg( test) ]
195
+ pub mod test_utils {
196
+ use crate :: {
197
+ DistinctType , Expression , FromClause , Identifier , QualifiedTableName , Select , SelectBody ,
198
+ SelectFromSubquery , SelectItem , SelectStatement ,
199
+ } ;
200
+
201
+ pub fn select_from_table ( table : QualifiedTableName ) -> SelectStatement {
202
+ SelectStatement {
203
+ with_cte : None ,
204
+ select : SelectBody :: Select ( Select {
205
+ distinct_type : DistinctType :: None ,
206
+ columns : vec ! [ SelectItem :: Expression ( Expression :: Identifier (
207
+ Identifier :: Wildcard ,
208
+ ) ) ] ,
209
+ from : Some ( FromClause :: Table ( table) ) ,
210
+ ..Default :: default ( )
211
+ } ) ,
212
+ order_by : None ,
213
+ limit : None ,
214
+ }
215
+ }
259
216
260
- // run_sunny_day_test(
261
- // "SELECT * FROM table_1 alias INDEXED BY index_1",
262
- // Statement::Select(expected_statement),
263
- // );
264
- // }
217
+ pub fn select_from_subquery ( subquery : SelectFromSubquery ) -> SelectStatement {
218
+ SelectStatement {
219
+ with_cte : None ,
220
+ select : SelectBody :: Select ( Select {
221
+ distinct_type : DistinctType :: None ,
222
+ columns : vec ! [ SelectItem :: Expression ( Expression :: Identifier (
223
+ Identifier :: Wildcard ,
224
+ ) ) ] ,
225
+ from : Some ( FromClause :: Subquery ( subquery) ) ,
226
+ ..Default :: default ( )
227
+ } ) ,
228
+ order_by : None ,
229
+ limit : None ,
230
+ }
231
+ }
232
+ }
265
233
266
- // #[test]
267
- // fn test_select_from_table_not_indexed() {
268
- // let expected_statement = select_from(FromClause::Table(QualifiedTableName {
269
- // table_id: Identifier::Single("table_1".to_string()),
270
- // alias: None,
271
- // indexed_type: Some(IndexedType::NotIndexed),
272
- // }));
234
+ #[ cfg( test) ]
235
+ mod select_from_table {
236
+ use super :: test_utils:: select_from_table;
237
+ use crate :: parser:: test_utils:: * ;
238
+ use crate :: { Identifier , IndexedType , QualifiedTableName , Statement } ;
239
+
240
+ #[ test]
241
+ fn select_from_table_test ( ) {
242
+ let expected_statement = select_from_table ( QualifiedTableName :: from ( Identifier :: Single (
243
+ "table_1" . to_string ( ) ,
244
+ ) ) ) ;
245
+
246
+ run_sunny_day_test (
247
+ "SELECT * FROM table_1" ,
248
+ Statement :: Select ( expected_statement) ,
249
+ ) ;
250
+ }
273
251
274
- // run_sunny_day_test(
275
- // "SELECT * FROM table_1 NOT INDEXED",
276
- // Statement::Select(expected_statement),
277
- // );
278
- // }
279
- // }
252
+ #[ test]
253
+ fn select_from_table_with_schema ( ) {
254
+ let expected_statement =
255
+ select_from_table ( QualifiedTableName :: from ( Identifier :: Compound ( vec ! [
256
+ "schema_1" . to_string( ) ,
257
+ "table_1" . to_string( ) ,
258
+ ] ) ) ) ;
259
+
260
+ run_sunny_day_test (
261
+ "SELECT * FROM schema_1.table_1" ,
262
+ Statement :: Select ( expected_statement) ,
263
+ ) ;
264
+ }
280
265
281
- // #[cfg(test)]
282
- // mod test_select_from_subquery {
283
- // use super::test_utils::{select_from, select_statement_with_columns};
284
- // use crate::parser::test_utils::*;
285
- // use crate::{
286
- // DistinctType, Expression, FromClause, Identifier, SelectBody, SelectFromSubquery, SelectItem, SelectStatement, Statement
287
- // };
266
+ #[ test]
267
+ fn select_from_table_with_alias ( ) {
268
+ let expected_statement = select_from_table ( QualifiedTableName {
269
+ table_id : Identifier :: Compound ( vec ! [ "schema_1" . to_string( ) , "table_1" . to_string( ) ] ) ,
270
+ alias : Some ( "alias" . to_string ( ) ) ,
271
+ indexed_type : None ,
272
+ } ) ;
273
+
274
+ run_sunny_day_test (
275
+ "SELECT * FROM schema_1.table_1 AS alias" ,
276
+ Statement :: Select ( expected_statement) ,
277
+ ) ;
278
+ }
288
279
289
- // #[test]
290
- // fn test_select_from_subquery() {
291
- // let expected_statement = select_from(FromClause::Subquery(SelectFromSubquery {
292
- // subquery: Box::new(SelectStatement::Select(select_statement_with_columns(
293
- // DistinctType::None,
294
- // vec![SelectItem::Expression(Expression::Identifier(
295
- // Identifier::Single("col1".to_string()),
296
- // ))],
297
- // ))),
298
- // alias: None,
299
- // }));
280
+ #[ test]
281
+ fn select_from_table_with_alias_without_as_keyword ( ) {
282
+ let expected_statement = select_from_table ( QualifiedTableName {
283
+ table_id : Identifier :: Single ( "table_1" . to_string ( ) ) ,
284
+ alias : Some ( "alias" . to_string ( ) ) ,
285
+ indexed_type : None ,
286
+ } ) ;
287
+
288
+ run_sunny_day_test (
289
+ "SELECT * FROM table_1 alias" ,
290
+ Statement :: Select ( expected_statement) ,
291
+ ) ;
292
+ }
300
293
301
- // run_sunny_day_test(
302
- // "SELECT * FROM (SELECT col1)",
303
- // Statement::Select(expected_statement),
304
- // );
305
- // }
294
+ #[ test]
295
+ fn select_from_table_with_alias_indexed ( ) {
296
+ let expected_statement = select_from_table ( QualifiedTableName {
297
+ table_id : Identifier :: Single ( "table_1" . to_string ( ) ) ,
298
+ alias : Some ( "alias" . to_string ( ) ) ,
299
+ indexed_type : Some ( IndexedType :: Indexed ( "index_1" . to_string ( ) ) ) ,
300
+ } ) ;
301
+
302
+ run_sunny_day_test (
303
+ "SELECT * FROM table_1 alias INDEXED BY index_1" ,
304
+ Statement :: Select ( expected_statement) ,
305
+ ) ;
306
+ }
306
307
307
- // #[test]
308
- // fn test_select_from_subquery_aliased() {
309
- // let expected_statement = select_from(FromClause::Subquery(SelectFromSubquery {
310
- // subquery: Box::new(SelectStatement {
311
- // with_cte: None,
312
- // select: SelectBody::Select(select_statement_with_columns(
313
- // DistinctType::None,
314
- // vec![SelectItem::Expression(Expression::Identifier(
315
- // Identifier::NameWithWildcard("t".to_string()),
316
- // ))],
317
- // )),
318
- // order_by: None,
319
- // limit: None,
320
- // }),
321
- // alias: Some("alias".to_string()),
322
- // }));
308
+ #[ test]
309
+ fn select_from_table_not_indexed ( ) {
310
+ let expected_statement = select_from_table ( QualifiedTableName {
311
+ table_id : Identifier :: Single ( "table_1" . to_string ( ) ) ,
312
+ alias : None ,
313
+ indexed_type : Some ( IndexedType :: NotIndexed ) ,
314
+ } ) ;
315
+
316
+ run_sunny_day_test (
317
+ "SELECT * FROM table_1 NOT INDEXED" ,
318
+ Statement :: Select ( expected_statement) ,
319
+ ) ;
320
+ }
321
+ }
323
322
324
- // run_sunny_day_test(
325
- // "SELECT * FROM (SELECT t.* ) as alias",
326
- // Statement::Select(expected_statement.clone()),
327
- // );
323
+ #[ cfg( test) ]
324
+ mod test_select_from_subquery {
325
+ use super :: test_utils:: { select_from_subquery, select_from_table} ;
326
+ use crate :: parser:: test_utils:: * ;
327
+ use crate :: { Identifier , QualifiedTableName , SelectFromSubquery , Statement } ;
328
+
329
+ #[ test]
330
+ fn select_from_subquery_test ( ) {
331
+ let expected_statement = select_from_subquery ( SelectFromSubquery {
332
+ subquery : Box :: new ( select_from_table ( QualifiedTableName :: from (
333
+ Identifier :: Single ( "table_1" . to_string ( ) ) ,
334
+ ) ) ) ,
335
+ alias : None ,
336
+ } ) ;
337
+
338
+ run_sunny_day_test (
339
+ "SELECT * FROM (SELECT * FROM table_1)" ,
340
+ Statement :: Select ( expected_statement) ,
341
+ ) ;
342
+ }
328
343
329
- // // without the as keyword
330
- // run_sunny_day_test(
331
- // "SELECT * FROM (SELECT t.* ) alias",
332
- // Statement::Select(expected_statement.clone()),
333
- // );
334
- // }
335
- // }
344
+ #[ test]
345
+ fn test_select_from_subquery_aliased ( ) {
346
+ let expected_statement = select_from_subquery ( SelectFromSubquery {
347
+ subquery : Box :: new ( select_from_table ( QualifiedTableName :: from (
348
+ Identifier :: Single ( "table_1" . to_string ( ) ) ,
349
+ ) ) ) ,
350
+ alias : Some ( "alias" . to_string ( ) ) ,
351
+ } ) ;
352
+
353
+ run_sunny_day_test (
354
+ "SELECT * FROM (SELECT * FROM table_1) as alias" ,
355
+ Statement :: Select ( expected_statement. clone ( ) ) ,
356
+ ) ;
357
+
358
+ // without the as keyword
359
+ run_sunny_day_test (
360
+ "SELECT * FROM (SELECT * FROM table_1) alias" ,
361
+ Statement :: Select ( expected_statement. clone ( ) ) ,
362
+ ) ;
363
+ }
364
+ }
336
365
337
366
// #[cfg(test)]
338
367
// mod test_select_from_table_function {
0 commit comments