Skip to content

Commit 5c6cf38

Browse files
committed
sql_parser: select statement parser refactoring(8)
1 parent 65fa82f commit 5c6cf38

File tree

2 files changed

+81
-81
lines changed

2 files changed

+81
-81
lines changed

src/parser/select/from/join.rs

+81
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,84 @@ mod select_from_with_join_clause_tests {
360360
);
361361
}
362362
}
363+
364+
#[cfg(test)]
365+
mod select_from_comma_separated_entries {
366+
use crate::parser::test_utils::*;
367+
use crate::select::from::test_utils::select_from;
368+
use crate::{
369+
FromClause, Identifier, IndexedType, JoinClause, JoinTable, JoinType, QualifiedTableName,
370+
SelectFromSubquery, Statement,
371+
};
372+
373+
#[test]
374+
fn test_select_from_comma_separated_table_or_subqueries() {
375+
fn join(lhs: FromClause, rhs: FromClause) -> FromClause {
376+
FromClause::Join(JoinClause {
377+
lhs_table: Box::new(lhs),
378+
join_tables: vec![JoinTable {
379+
join_type: JoinType::Cross,
380+
table: Box::new(rhs),
381+
constraints: None,
382+
}],
383+
})
384+
}
385+
386+
let table_1 = FromClause::Table(QualifiedTableName::from(Identifier::Single(
387+
"table_1".to_string(),
388+
)));
389+
let schema2_table2 =
390+
FromClause::Table(QualifiedTableName::from(Identifier::Compound(vec![
391+
"schema2".to_string(),
392+
"table2".to_string(),
393+
])));
394+
395+
let schema3_table3 = FromClause::Table(QualifiedTableName {
396+
table_id: Identifier::Compound(vec!["schema3".to_string(), "table3".to_string()]),
397+
alias: Some("table3_alias".to_string()),
398+
indexed_type: None,
399+
});
400+
401+
let indexed_table = FromClause::Table(QualifiedTableName {
402+
table_id: Identifier::Single("indexed_table".to_string()),
403+
alias: Some("t1".to_string()),
404+
indexed_type: Some(IndexedType::Indexed("index_1".to_string())),
405+
});
406+
407+
let not_indexed_table = FromClause::Table(QualifiedTableName {
408+
table_id: Identifier::Single("not_indexed_table".to_string()),
409+
alias: Some("t2".to_string()),
410+
indexed_type: Some(IndexedType::NotIndexed),
411+
});
412+
413+
let subquery = FromClause::Subquery(SelectFromSubquery {
414+
subquery: Box::new(select_from(FromClause::Table(QualifiedTableName::from(
415+
Identifier::Single("table_2".to_string()),
416+
)))),
417+
alias: Some("select_alias".to_string()),
418+
});
419+
420+
let expected_statement = select_from(FromClause::Froms(vec![join(
421+
table_1,
422+
join(
423+
schema2_table2,
424+
join(
425+
schema3_table3,
426+
join(indexed_table, join(not_indexed_table, subquery)),
427+
),
428+
),
429+
)]));
430+
431+
run_sunny_day_test(
432+
"SELECT * FROM (
433+
table_1,
434+
schema2.table2,
435+
schema3.table3 as table3_alias,
436+
indexed_table as t1 INDEXED BY index_1,
437+
not_indexed_table as t2 NOT INDEXED,
438+
(SELECT * FROM table_2) as select_alias
439+
)",
440+
Statement::Select(expected_statement),
441+
);
442+
}
443+
}

src/parser/select/from/mod.rs

-81
Original file line numberDiff line numberDiff line change
@@ -150,84 +150,3 @@ mod select_from_table {
150150
);
151151
}
152152
}
153-
154-
// #[cfg(test)]
155-
// mod test_select_from_comma_separated_table_or_subqueries {
156-
// use super::test_utils::select_from;
157-
// use crate::parser::test_utils::*;
158-
// use crate::{
159-
// FromClause, Identifier, IndexedType, JoinClause, JoinTable, JoinType, QualifiedTableName,
160-
// SelectFromSubquery, Statement,
161-
// };
162-
163-
// #[test]
164-
// fn test_select_from_comma_separated_table_or_subqueries() {
165-
// fn join(lhs: FromClause, rhs: FromClause) -> FromClause {
166-
// FromClause::Join(JoinClause {
167-
// lhs_table: Box::new(lhs),
168-
// join_tables: vec![JoinTable {
169-
// join_type: JoinType::Cross,
170-
// table: Box::new(rhs),
171-
// constraints: None,
172-
// }],
173-
// })
174-
// }
175-
176-
// let table_1 = FromClause::Table(QualifiedTableName::from(Identifier::Single(
177-
// "table_1".to_string(),
178-
// )));
179-
// let schema2_table2 =
180-
// FromClause::Table(QualifiedTableName::from(Identifier::Compound(vec![
181-
// "schema2".to_string(),
182-
// "table2".to_string(),
183-
// ])));
184-
185-
// let schema3_table3 = FromClause::Table(QualifiedTableName {
186-
// table_id: Identifier::Compound(vec!["schema3".to_string(), "table3".to_string()]),
187-
// alias: Some("table3_alias".to_string()),
188-
// indexed_type: None,
189-
// });
190-
191-
// let indexed_table = FromClause::Table(QualifiedTableName {
192-
// table_id: Identifier::Single("indexed_table".to_string()),
193-
// alias: Some("t1".to_string()),
194-
// indexed_type: Some(IndexedType::Indexed("index_1".to_string())),
195-
// });
196-
197-
// let not_indexed_table = FromClause::Table(QualifiedTableName {
198-
// table_id: Identifier::Single("not_indexed_table".to_string()),
199-
// alias: Some("t2".to_string()),
200-
// indexed_type: Some(IndexedType::NotIndexed),
201-
// });
202-
203-
// let subquery = FromClause::Subquery(SelectFromSubquery {
204-
// subquery: Box::new(select_from(FromClause::Table(QualifiedTableName::from(
205-
// Identifier::Single("table_2".to_string()),
206-
// )))),
207-
// alias: Some("select_alias".to_string()),
208-
// });
209-
210-
// let expected_statement = select_from(FromClause::Froms(vec![join(
211-
// table_1,
212-
// join(
213-
// schema2_table2,
214-
// join(
215-
// schema3_table3,
216-
// join(indexed_table, join(not_indexed_table, subquery)),
217-
// ),
218-
// ),
219-
// )]));
220-
221-
// run_sunny_day_test(
222-
// "SELECT * FROM (
223-
// table_1,
224-
// schema2.table2,
225-
// schema3.table3 as table3_alias,
226-
// indexed_table as t1 INDEXED BY index_1,
227-
// not_indexed_table as t2 NOT INDEXED,
228-
// (SELECT * FROM table_2) as select_alias
229-
// )",
230-
// Statement::Select(expected_statement),
231-
// );
232-
// }
233-
// }

0 commit comments

Comments
 (0)