Skip to content

Commit

Permalink
add roundtrip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devinjdangelo committed Mar 13, 2024
1 parent 7228490 commit a2e8b61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Default features:
- `parquet`: support for reading the [Apache Parquet] format
- `regex_expressions`: regular expression functions, such as `regexp_match`
- `unicode_expressions`: Include unicode aware functions such as `character_length`
- `unparser` : enables support to reverse LogicalPlans back into SQL

Optional features:

Expand Down
4 changes: 2 additions & 2 deletions datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ impl Unparser<'_> {
DataType::Binary => todo!(),
DataType::FixedSizeBinary(_) => todo!(),
DataType::LargeBinary => todo!(),
DataType::Utf8 => todo!(),
DataType::LargeUtf8 => todo!(),
DataType::Utf8 => Ok(ast::DataType::Varchar(None)),
DataType::LargeUtf8 => Ok(ast::DataType::Text),
DataType::List(_) => todo!(),
DataType::FixedSizeList(_, _) => todo!(),
DataType::LargeList(_) => todo!(),
Expand Down
17 changes: 10 additions & 7 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4493,8 +4493,11 @@ impl TableSource for EmptyTable {
#[test]
fn roundtrip_expr() {
let tests: Vec<(TableReference, &str, &str)> = vec![
(TableReference::bare("person"), "age > 35", "age > 35"),
(TableReference::bare("person"), "id = '10'", "id = '10'"),
(TableReference::bare("person"), "age > 35", "(age > 35)"),
(TableReference::bare("person"), "id = '10'", "(id = '10')"),
(TableReference::bare("person"), "CAST(id AS VARCHAR)", "CAST(id AS VARCHAR)"),
(TableReference::bare("person"), "SUM((age * 2))", "SUM((age * 2))"),

];

let roundtrip = |table, sql: &str| -> Result<String> {
Expand Down Expand Up @@ -4540,15 +4543,15 @@ fn roundtrip_statement() {
),
(
"select ta.j1_id from j1 ta where ta.j1_id > 1;",
r#"SELECT ta.j1_id FROM j1 AS ta WHERE ta.j1_id > 1"#,
r#"SELECT ta.j1_id FROM j1 AS ta WHERE (ta.j1_id > 1)"#,
),
(
"select ta.j1_id, tb.j2_string from j1 ta join j2 tb on ta.j1_id = tb.j2_id;",
r#"SELECT ta.j1_id, tb.j2_string FROM j1 AS ta JOIN j2 AS tb ON ta.j1_id = tb.j2_id"#,
"select ta.j1_id, tb.j2_string from j1 ta join j2 tb on (ta.j1_id = tb.j2_id);",
r#"SELECT ta.j1_id, tb.j2_string FROM j1 AS ta JOIN j2 AS tb ON (ta.j1_id = tb.j2_id)"#,
),
(
"select ta.j1_id, tb.j2_string, tc.j3_string from j1 ta join j2 tb on ta.j1_id = tb.j2_id join j3 tc on ta.j1_id = tc.j3_id;",
r#"SELECT ta.j1_id, tb.j2_string, tc.j3_string FROM j1 AS ta JOIN j2 AS tb ON ta.j1_id = tb.j2_id JOIN j3 AS tc ON ta.j1_id = tc.j3_id"#,
"select ta.j1_id, tb.j2_string, tc.j3_string from j1 ta join j2 tb on (ta.j1_id = tb.j2_id) join j3 tc on (ta.j1_id = tc.j3_id);",
r#"SELECT ta.j1_id, tb.j2_string, tc.j3_string FROM j1 AS ta JOIN j2 AS tb ON (ta.j1_id = tb.j2_id) JOIN j3 AS tc ON (ta.j1_id = tc.j3_id)"#,
),
];

Expand Down

0 comments on commit a2e8b61

Please sign in to comment.