Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make binary operator formatting consistent between logical and physical plans #3331

Merged
merged 5 commits into from
Sep 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert cast change
andygrove committed Sep 1, 2022
commit baf3016cef80d76b48fedb1089a1eec7abcf0b92
12 changes: 6 additions & 6 deletions datafusion/core/src/physical_plan/planner.rs
Original file line number Diff line number Diff line change
@@ -128,13 +128,13 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result<String> {
name += "END";
Ok(name)
}
Expr::Cast { expr, .. } => {
// CAST does not change the name of an expression. It just changes the type.
create_physical_name(expr, false)
Expr::Cast { expr, data_type } => {
let expr = create_physical_name(expr, false)?;
Ok(format!("CAST({} AS {:?})", expr, data_type))
}
Expr::TryCast { expr, .. } => {
// TRY_CAST does not change the name of an expression. It just changes the type.
create_physical_name(expr, false)
Expr::TryCast { expr, data_type } => {
let expr = create_physical_name(expr, false)?;
Ok(format!("TRY_CAST({} AS {:?})", expr, data_type))
}
Expr::Not(expr) => {
let expr = create_physical_name(expr, false)?;
16 changes: 8 additions & 8 deletions datafusion/core/tests/dataframe_functions.rs
Original file line number Diff line number Diff line change
@@ -667,14 +667,14 @@ async fn test_fn_substr() -> Result<()> {
async fn test_cast() -> Result<()> {
let expr = cast(col("b"), DataType::Float64);
let expected = vec![
"+--------+",
"| test.b |",
"+--------+",
"| 1 |",
"| 10 |",
"| 10 |",
"| 100 |",
"+--------+",
"+-------------------------+",
"| CAST(test.b AS Float64) |",
"+-------------------------+",
"| 1 |",
"| 10 |",
"| 10 |",
"| 100 |",
"+-------------------------+",
];

assert_fn_batches!(expr, expected);
10 changes: 5 additions & 5 deletions datafusion/core/tests/sql/aggregates.rs
Original file line number Diff line number Diff line change
@@ -462,11 +462,11 @@ async fn csv_query_external_table_sum() {
"SELECT SUM(CAST(c7 AS BIGINT)), SUM(CAST(c8 AS BIGINT)) FROM aggregate_test_100";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+----------------------------+----------------------------+",
"| SUM(aggregate_test_100.c7) | SUM(aggregate_test_100.c8) |",
"+----------------------------+----------------------------+",
"| 13060 | 3017641 |",
"+----------------------------+----------------------------+",
"+-------------------------------------------+-------------------------------------------+",
"| SUM(CAST(aggregate_test_100.c7 AS Int64)) | SUM(CAST(aggregate_test_100.c8 AS Int64)) |",
"+-------------------------------------------+-------------------------------------------+",
"| 13060 | 3017641 |",
"+-------------------------------------------+-------------------------------------------+",
];
assert_batches_eq!(expected, &actual);
}
44 changes: 22 additions & 22 deletions datafusion/core/tests/sql/functions.rs
Original file line number Diff line number Diff line change
@@ -43,12 +43,12 @@ async fn csv_query_cast() -> Result<()> {
let actual = execute_to_batches(&ctx, sql).await;

let expected = vec![
"+------------------------+",
"| aggregate_test_100.c12 |",
"+------------------------+",
"| 0.39144436 |",
"| 0.3887028 |",
"+------------------------+",
"+-----------------------------------------+",
"| CAST(aggregate_test_100.c12 AS Float32) |",
"+-----------------------------------------+",
"| 0.39144436 |",
"| 0.3887028 |",
"+-----------------------------------------+",
];

assert_batches_eq!(expected, &actual);
@@ -98,14 +98,14 @@ async fn query_concat() -> Result<()> {
let sql = "SELECT concat(c1, '-hi-', cast(c2 as varchar)) FROM test";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+--------------------------------------+",
"| concat(test.c1,Utf8(\"-hi-\"),test.c2) |",
"+--------------------------------------+",
"| -hi-0 |",
"| a-hi-1 |",
"| aa-hi- |",
"| aaa-hi-3 |",
"+--------------------------------------+",
"+----------------------------------------------------+",
"| concat(test.c1,Utf8(\"-hi-\"),CAST(test.c2 AS Utf8)) |",
"+----------------------------------------------------+",
"| -hi-0 |",
"| a-hi-1 |",
"| aa-hi- |",
"| aaa-hi-3 |",
"+----------------------------------------------------+",
];
assert_batches_eq!(expected, &actual);
Ok(())
@@ -133,14 +133,14 @@ async fn query_array() -> Result<()> {
let sql = "SELECT make_array(c1, cast(c2 as varchar)) FROM test";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+----------------------------+",
"| makearray(test.c1,test.c2) |",
"+----------------------------+",
"| [, 0] |",
"| [a, 1] |",
"| [aa, ] |",
"| [aaa, 3] |",
"+----------------------------+",
"+------------------------------------------+",
"| makearray(test.c1,CAST(test.c2 AS Utf8)) |",
"+------------------------------------------+",
"| [, 0] |",
"| [a, 1] |",
"| [aa, ] |",
"| [aaa, 3] |",
"+------------------------------------------+",
];
assert_batches_eq!(expected, &actual);
Ok(())
24 changes: 12 additions & 12 deletions datafusion/core/tests/sql/parquet.rs
Original file line number Diff line number Diff line change
@@ -31,18 +31,18 @@ async fn parquet_query() {
let sql = "SELECT id, CAST(string_col AS varchar) FROM alltypes_plain";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+----+---------------------------+",
"| id | alltypes_plain.string_col |",
"+----+---------------------------+",
"| 4 | 0 |",
"| 5 | 1 |",
"| 6 | 0 |",
"| 7 | 1 |",
"| 2 | 0 |",
"| 3 | 1 |",
"| 0 | 0 |",
"| 1 | 1 |",
"+----+---------------------------+",
"+----+-----------------------------------------+",
"| id | CAST(alltypes_plain.string_col AS Utf8) |",
"+----+-----------------------------------------+",
"| 4 | 0 |",
"| 5 | 1 |",
"| 6 | 0 |",
"| 7 | 1 |",
"| 2 | 0 |",
"| 3 | 1 |",
"| 0 | 0 |",
"| 1 | 1 |",
"+----+-----------------------------------------+",
];

assert_batches_eq!(expected, &actual);