From c612c264ad60788e0b2a01967dd9dfb7c05be228 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Thu, 1 Sep 2022 06:43:56 -0600 Subject: [PATCH 1/4] Change name of physical CAST expression --- datafusion/core/src/physical_plan/planner.rs | 12 +++--- datafusion/core/tests/dataframe_functions.rs | 16 +++---- datafusion/core/tests/sql/aggregates.rs | 10 ++--- datafusion/core/tests/sql/functions.rs | 44 ++++++++++---------- datafusion/core/tests/sql/parquet.rs | 24 +++++------ 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/datafusion/core/src/physical_plan/planner.rs b/datafusion/core/src/physical_plan/planner.rs index a67e2dac7c22..3823e638bf14 100644 --- a/datafusion/core/src/physical_plan/planner.rs +++ b/datafusion/core/src/physical_plan/planner.rs @@ -128,13 +128,13 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result { name += "END"; Ok(name) } - Expr::Cast { expr, data_type } => { - let expr = create_physical_name(expr, false)?; - Ok(format!("CAST({} AS {:?})", expr, data_type)) + Expr::Cast { expr, .. } => { + // 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::TryCast { expr, .. } => { + // TRY_CAST does not change the name of an expression. It just changes the type. + create_physical_name(expr, false) } Expr::Not(expr) => { let expr = create_physical_name(expr, false)?; diff --git a/datafusion/core/tests/dataframe_functions.rs b/datafusion/core/tests/dataframe_functions.rs index 19694285cc31..0d3631b18a70 100644 --- a/datafusion/core/tests/dataframe_functions.rs +++ b/datafusion/core/tests/dataframe_functions.rs @@ -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![ - "+-------------------------+", - "| CAST(test.b AS Float64) |", - "+-------------------------+", - "| 1 |", - "| 10 |", - "| 10 |", - "| 100 |", - "+-------------------------+", + "+--------+", + "| test.b |", + "+--------+", + "| 1 |", + "| 10 |", + "| 10 |", + "| 100 |", + "+--------+", ]; assert_fn_batches!(expr, expected); diff --git a/datafusion/core/tests/sql/aggregates.rs b/datafusion/core/tests/sql/aggregates.rs index 9be41afa26a2..4a368eaeb032 100644 --- a/datafusion/core/tests/sql/aggregates.rs +++ b/datafusion/core/tests/sql/aggregates.rs @@ -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(CAST(aggregate_test_100.c7 AS Int64)) | SUM(CAST(aggregate_test_100.c8 AS Int64)) |", - "+-------------------------------------------+-------------------------------------------+", - "| 13060 | 3017641 |", - "+-------------------------------------------+-------------------------------------------+", + "+----------------------------+----------------------------+", + "| SUM(aggregate_test_100.c7) | SUM(aggregate_test_100.c8) |", + "+----------------------------+----------------------------+", + "| 13060 | 3017641 |", + "+----------------------------+----------------------------+", ]; assert_batches_eq!(expected, &actual); } diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs index e780e7e0f81a..369dfeb0b570 100644 --- a/datafusion/core/tests/sql/functions.rs +++ b/datafusion/core/tests/sql/functions.rs @@ -43,12 +43,12 @@ async fn csv_query_cast() -> Result<()> { let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+-----------------------------------------+", - "| CAST(aggregate_test_100.c12 AS Float32) |", - "+-----------------------------------------+", - "| 0.39144436 |", - "| 0.3887028 |", - "+-----------------------------------------+", + "+------------------------+", + "| aggregate_test_100.c12 |", + "+------------------------+", + "| 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-\"),CAST(test.c2 AS Utf8)) |", - "+----------------------------------------------------+", - "| -hi-0 |", - "| a-hi-1 |", - "| aa-hi- |", - "| aaa-hi-3 |", - "+----------------------------------------------------+", + "+--------------------------------------+", + "| concat(test.c1,Utf8(\"-hi-\"),test.c2) |", + "+--------------------------------------+", + "| -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,CAST(test.c2 AS Utf8)) |", - "+------------------------------------------+", - "| [, 0] |", - "| [a, 1] |", - "| [aa, ] |", - "| [aaa, 3] |", - "+------------------------------------------+", + "+----------------------------+", + "| makearray(test.c1,test.c2) |", + "+----------------------------+", + "| [, 0] |", + "| [a, 1] |", + "| [aa, ] |", + "| [aaa, 3] |", + "+----------------------------+", ]; assert_batches_eq!(expected, &actual); Ok(()) diff --git a/datafusion/core/tests/sql/parquet.rs b/datafusion/core/tests/sql/parquet.rs index 51304f60876c..8bec4f1dd3db 100644 --- a/datafusion/core/tests/sql/parquet.rs +++ b/datafusion/core/tests/sql/parquet.rs @@ -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 | CAST(alltypes_plain.string_col AS Utf8) |", - "+----+-----------------------------------------+", - "| 4 | 0 |", - "| 5 | 1 |", - "| 6 | 0 |", - "| 7 | 1 |", - "| 2 | 0 |", - "| 3 | 1 |", - "| 0 | 0 |", - "| 1 | 1 |", - "+----+-----------------------------------------+", + "+----+---------------------------+", + "| id | alltypes_plain.string_col |", + "+----+---------------------------+", + "| 4 | 0 |", + "| 5 | 1 |", + "| 6 | 0 |", + "| 7 | 1 |", + "| 2 | 0 |", + "| 3 | 1 |", + "| 0 | 0 |", + "| 1 | 1 |", + "+----+---------------------------+", ]; assert_batches_eq!(expected, &actual); From 95129d19603558ad88b28bfa05fa2037be9885e7 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Thu, 1 Sep 2022 08:32:22 -0600 Subject: [PATCH 2/4] Use Display formatting instead of Debug formatting for operators in physical expressions --- datafusion/core/src/physical_plan/planner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/core/src/physical_plan/planner.rs b/datafusion/core/src/physical_plan/planner.rs index 3823e638bf14..1a165b1ce0e7 100644 --- a/datafusion/core/src/physical_plan/planner.rs +++ b/datafusion/core/src/physical_plan/planner.rs @@ -108,7 +108,7 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result { Expr::BinaryExpr { left, op, right } => { let left = create_physical_name(left, false)?; let right = create_physical_name(right, false)?; - Ok(format!("{} {:?} {}", left, op, right)) + Ok(format!("{} {} {}", left, op, right)) } Expr::Case { expr, From fe26486735f7791eabbd38612d350a5b02f7f22e Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Thu, 1 Sep 2022 08:46:14 -0600 Subject: [PATCH 3/4] Update tests --- datafusion/core/src/execution/context.rs | 10 +- datafusion/core/tests/sql/aggregates.rs | 10 +- datafusion/core/tests/sql/decimal.rs | 304 +++++++++---------- datafusion/core/tests/sql/expr.rs | 16 +- datafusion/core/tests/sql/functions.rs | 16 +- datafusion/core/tests/sql/select.rs | 26 +- datafusion/core/tests/sql/timestamp.rs | 369 ++++++++++++----------- datafusion/core/tests/sql/window.rs | 12 +- 8 files changed, 382 insertions(+), 381 deletions(-) diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rs index 0b16181467a8..70a29f5a7ced 100644 --- a/datafusion/core/src/execution/context.rs +++ b/datafusion/core/src/execution/context.rs @@ -1849,11 +1849,11 @@ mod tests { .await?; let expected = vec![ - "+----------------------+------------------------+------------------------+", - "| @@version | @name | @integer Plus Int64(1) |", - "+----------------------+------------------------+------------------------+", - "| system-var-@@version | user-defined-var-@name | 42 |", - "+----------------------+------------------------+------------------------+", + "+----------------------+------------------------+---------------------+", + "| @@version | @name | @integer + Int64(1) |", + "+----------------------+------------------------+---------------------+", + "| system-var-@@version | user-defined-var-@name | 42 |", + "+----------------------+------------------------+---------------------+", ]; assert_batches_eq!(expected, &results); diff --git a/datafusion/core/tests/sql/aggregates.rs b/datafusion/core/tests/sql/aggregates.rs index 4a368eaeb032..deabe5c12eda 100644 --- a/datafusion/core/tests/sql/aggregates.rs +++ b/datafusion/core/tests/sql/aggregates.rs @@ -1815,11 +1815,11 @@ async fn aggregate_avg_add() -> Result<()> { assert_eq!(results.len(), 1); let expected = vec![ - "+--------------+----------------------------+----------------------------+----------------------------+", - "| AVG(test.c1) | AVG(test.c1) Plus Int64(1) | AVG(test.c1) Plus Int64(2) | Int64(1) Plus AVG(test.c1) |", - "+--------------+----------------------------+----------------------------+----------------------------+", - "| 1.5 | 2.5 | 3.5 | 2.5 |", - "+--------------+----------------------------+----------------------------+----------------------------+", + "+--------------+-------------------------+-------------------------+-------------------------+", + "| AVG(test.c1) | AVG(test.c1) + Int64(1) | AVG(test.c1) + Int64(2) | Int64(1) + AVG(test.c1) |", + "+--------------+-------------------------+-------------------------+-------------------------+", + "| 1.5 | 2.5 | 3.5 | 2.5 |", + "+--------------+-------------------------+-------------------------+-------------------------+", ]; assert_batches_sorted_eq!(expected, &results); diff --git a/datafusion/core/tests/sql/decimal.rs b/datafusion/core/tests/sql/decimal.rs index 9b16ca53462b..8ded8752dfcb 100644 --- a/datafusion/core/tests/sql/decimal.rs +++ b/datafusion/core/tests/sql/decimal.rs @@ -376,25 +376,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+---------------------------------+", - "| decimal_simple.c1 Plus Int64(1) |", - "+---------------------------------+", - "| 1.000010 |", - "| 1.000020 |", - "| 1.000020 |", - "| 1.000030 |", - "| 1.000030 |", - "| 1.000030 |", - "| 1.000040 |", - "| 1.000040 |", - "| 1.000040 |", - "| 1.000040 |", - "| 1.000050 |", - "| 1.000050 |", - "| 1.000050 |", - "| 1.000050 |", - "| 1.000050 |", - "+---------------------------------+", + "+------------------------------+", + "| decimal_simple.c1 + Int64(1) |", + "+------------------------------+", + "| 1.000010 |", + "| 1.000020 |", + "| 1.000020 |", + "| 1.000030 |", + "| 1.000030 |", + "| 1.000030 |", + "| 1.000040 |", + "| 1.000040 |", + "| 1.000040 |", + "| 1.000040 |", + "| 1.000050 |", + "| 1.000050 |", + "| 1.000050 |", + "| 1.000050 |", + "| 1.000050 |", + "+------------------------------+", ]; assert_batches_eq!(expected, &actual); // array decimal(10,6) + array decimal(12,7) => decimal(13,7) @@ -405,25 +405,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+------------------------------------------+", - "| decimal_simple.c1 Plus decimal_simple.c5 |", - "+------------------------------------------+", - "| 0.0000240 |", - "| 0.0000450 |", - "| 0.0000390 |", - "| 0.0000620 |", - "| 0.0000650 |", - "| 0.0000410 |", - "| 0.0000840 |", - "| 0.0000800 |", - "| 0.0000800 |", - "| 0.0000840 |", - "| 0.0001020 |", - "| 0.0001280 |", - "| 0.0000830 |", - "| 0.0001180 |", - "| 0.0001500 |", - "+------------------------------------------+", + "+---------------------------------------+", + "| decimal_simple.c1 + decimal_simple.c5 |", + "+---------------------------------------+", + "| 0.0000240 |", + "| 0.0000450 |", + "| 0.0000390 |", + "| 0.0000620 |", + "| 0.0000650 |", + "| 0.0000410 |", + "| 0.0000840 |", + "| 0.0000800 |", + "| 0.0000800 |", + "| 0.0000840 |", + "| 0.0001020 |", + "| 0.0001280 |", + "| 0.0000830 |", + "| 0.0001180 |", + "| 0.0001500 |", + "+---------------------------------------+", ]; assert_batches_eq!(expected, &actual); // subtract @@ -434,25 +434,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+----------------------------------+", - "| decimal_simple.c1 Minus Int64(1) |", - "+----------------------------------+", - "| -0.999990 |", - "| -0.999980 |", - "| -0.999980 |", - "| -0.999970 |", - "| -0.999970 |", - "| -0.999970 |", - "| -0.999960 |", - "| -0.999960 |", - "| -0.999960 |", - "| -0.999960 |", - "| -0.999950 |", - "| -0.999950 |", - "| -0.999950 |", - "| -0.999950 |", - "| -0.999950 |", - "+----------------------------------+", + "+------------------------------+", + "| decimal_simple.c1 - Int64(1) |", + "+------------------------------+", + "| -0.999990 |", + "| -0.999980 |", + "| -0.999980 |", + "| -0.999970 |", + "| -0.999970 |", + "| -0.999970 |", + "| -0.999960 |", + "| -0.999960 |", + "| -0.999960 |", + "| -0.999960 |", + "| -0.999950 |", + "| -0.999950 |", + "| -0.999950 |", + "| -0.999950 |", + "| -0.999950 |", + "+------------------------------+", ]; assert_batches_eq!(expected, &actual); @@ -463,25 +463,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+-------------------------------------------+", - "| decimal_simple.c1 Minus decimal_simple.c5 |", - "+-------------------------------------------+", - "| -0.0000040 |", - "| -0.0000050 |", - "| 0.0000010 |", - "| -0.0000020 |", - "| -0.0000050 |", - "| 0.0000190 |", - "| -0.0000040 |", - "| 0.0000000 |", - "| 0.0000000 |", - "| -0.0000040 |", - "| -0.0000020 |", - "| -0.0000280 |", - "| 0.0000170 |", - "| -0.0000180 |", - "| -0.0000500 |", - "+-------------------------------------------+", + "+---------------------------------------+", + "| decimal_simple.c1 - decimal_simple.c5 |", + "+---------------------------------------+", + "| -0.0000040 |", + "| -0.0000050 |", + "| 0.0000010 |", + "| -0.0000020 |", + "| -0.0000050 |", + "| 0.0000190 |", + "| -0.0000040 |", + "| 0.0000000 |", + "| 0.0000000 |", + "| -0.0000040 |", + "| -0.0000020 |", + "| -0.0000280 |", + "| 0.0000170 |", + "| -0.0000180 |", + "| -0.0000500 |", + "+---------------------------------------+", ]; assert_batches_eq!(expected, &actual); // multiply @@ -492,25 +492,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+--------------------------------------+", - "| decimal_simple.c1 Multiply Int64(20) |", - "+--------------------------------------+", - "| 0.000200 |", - "| 0.000400 |", - "| 0.000400 |", - "| 0.000600 |", - "| 0.000600 |", - "| 0.000600 |", - "| 0.000800 |", - "| 0.000800 |", - "| 0.000800 |", - "| 0.000800 |", - "| 0.001000 |", - "| 0.001000 |", - "| 0.001000 |", - "| 0.001000 |", - "| 0.001000 |", - "+--------------------------------------+", + "+-------------------------------+", + "| decimal_simple.c1 * Int64(20) |", + "+-------------------------------+", + "| 0.000200 |", + "| 0.000400 |", + "| 0.000400 |", + "| 0.000600 |", + "| 0.000600 |", + "| 0.000600 |", + "| 0.000800 |", + "| 0.000800 |", + "| 0.000800 |", + "| 0.000800 |", + "| 0.001000 |", + "| 0.001000 |", + "| 0.001000 |", + "| 0.001000 |", + "| 0.001000 |", + "+-------------------------------+", ]; assert_batches_eq!(expected, &actual); @@ -521,25 +521,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+----------------------------------------------+", - "| decimal_simple.c1 Multiply decimal_simple.c5 |", - "+----------------------------------------------+", - "| 0.0000000001400 |", - "| 0.0000000005000 |", - "| 0.0000000003800 |", - "| 0.0000000009600 |", - "| 0.0000000010500 |", - "| 0.0000000003300 |", - "| 0.0000000017600 |", - "| 0.0000000016000 |", - "| 0.0000000016000 |", - "| 0.0000000017600 |", - "| 0.0000000026000 |", - "| 0.0000000039000 |", - "| 0.0000000016500 |", - "| 0.0000000034000 |", - "| 0.0000000050000 |", - "+----------------------------------------------+", + "+---------------------------------------+", + "| decimal_simple.c1 * decimal_simple.c5 |", + "+---------------------------------------+", + "| 0.0000000001400 |", + "| 0.0000000005000 |", + "| 0.0000000003800 |", + "| 0.0000000009600 |", + "| 0.0000000010500 |", + "| 0.0000000003300 |", + "| 0.0000000017600 |", + "| 0.0000000016000 |", + "| 0.0000000016000 |", + "| 0.0000000017600 |", + "| 0.0000000026000 |", + "| 0.0000000039000 |", + "| 0.0000000016500 |", + "| 0.0000000034000 |", + "| 0.0000000050000 |", + "+---------------------------------------+", ]; assert_batches_eq!(expected, &actual); // divide @@ -579,25 +579,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+--------------------------------------------+", - "| decimal_simple.c1 Divide decimal_simple.c5 |", - "+--------------------------------------------+", - "| 0.7142857142857143296 |", - "| 0.8000000000000000000 |", - "| 1.0526315789473683456 |", - "| 0.9375000000000000000 |", - "| 0.8571428571428571136 |", - "| 2.7272727272727269376 |", - "| 0.9090909090909090816 |", - "| 1.0000000000000000000 |", - "| 1.0000000000000000000 |", - "| 0.9090909090909090816 |", - "| 0.9615384615384614912 |", - "| 0.6410256410256410624 |", - "| 1.5151515151515152384 |", - "| 0.7352941176470588416 |", - "| 0.5000000000000000000 |", - "+--------------------------------------------+", + "+---------------------------------------+", + "| decimal_simple.c1 / decimal_simple.c5 |", + "+---------------------------------------+", + "| 0.7142857142857143296 |", + "| 0.8000000000000000000 |", + "| 1.0526315789473683456 |", + "| 0.9375000000000000000 |", + "| 0.8571428571428571136 |", + "| 2.7272727272727269376 |", + "| 0.9090909090909090816 |", + "| 1.0000000000000000000 |", + "| 1.0000000000000000000 |", + "| 0.9090909090909090816 |", + "| 0.9615384615384614912 |", + "| 0.6410256410256410624 |", + "| 1.5151515151515152384 |", + "| 0.7352941176470588416 |", + "| 0.5000000000000000000 |", + "+---------------------------------------+", ]; assert_batches_eq!(expected, &actual); @@ -638,25 +638,25 @@ async fn decimal_arithmetic_op() -> Result<()> { actual[0].schema().field(0).data_type() ); let expected = vec![ - "+--------------------------------------------+", - "| decimal_simple.c1 Modulo decimal_simple.c5 |", - "+--------------------------------------------+", - "| 0.0000100 |", - "| 0.0000200 |", - "| 0.0000010 |", - "| 0.0000300 |", - "| 0.0000300 |", - "| 0.0000080 |", - "| 0.0000400 |", - "| 0.0000000 |", - "| 0.0000000 |", - "| 0.0000400 |", - "| 0.0000500 |", - "| 0.0000500 |", - "| 0.0000170 |", - "| 0.0000500 |", - "| 0.0000500 |", - "+--------------------------------------------+", + "+---------------------------------------+", + "| decimal_simple.c1 % decimal_simple.c5 |", + "+---------------------------------------+", + "| 0.0000100 |", + "| 0.0000200 |", + "| 0.0000010 |", + "| 0.0000300 |", + "| 0.0000300 |", + "| 0.0000080 |", + "| 0.0000400 |", + "| 0.0000000 |", + "| 0.0000000 |", + "| 0.0000400 |", + "| 0.0000500 |", + "| 0.0000500 |", + "| 0.0000170 |", + "| 0.0000500 |", + "| 0.0000500 |", + "+---------------------------------------+", ]; assert_batches_eq!(expected, &actual); diff --git a/datafusion/core/tests/sql/expr.rs b/datafusion/core/tests/sql/expr.rs index 22e3b0358ce5..ae94629f8691 100644 --- a/datafusion/core/tests/sql/expr.rs +++ b/datafusion/core/tests/sql/expr.rs @@ -561,14 +561,14 @@ async fn query_scalar_minus_array() -> Result<()> { let sql = "SELECT 4 - c1 FROM test"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+------------------------+", - "| Int64(4) Minus test.c1 |", - "+------------------------+", - "| 4 |", - "| 3 |", - "| |", - "| 1 |", - "+------------------------+", + "+--------------------+", + "| Int64(4) - test.c1 |", + "+--------------------+", + "| 4 |", + "| 3 |", + "| |", + "| 1 |", + "+--------------------+", ]; assert_batches_eq!(expected, &actual); Ok(()) diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs index 369dfeb0b570..a1594393cc21 100644 --- a/datafusion/core/tests/sql/functions.rs +++ b/datafusion/core/tests/sql/functions.rs @@ -333,14 +333,14 @@ async fn coalesce_mul_with_default_value() -> Result<()> { let sql = "SELECT COALESCE(c1 * c2, 0) FROM test"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+---------------------------------------------+", - "| coalesce(test.c1 Multiply test.c2,Int64(0)) |", - "+---------------------------------------------+", - "| 2 |", - "| 0 |", - "| 0 |", - "| 0 |", - "+---------------------------------------------+", + "+--------------------------------------+", + "| coalesce(test.c1 * test.c2,Int64(0)) |", + "+--------------------------------------+", + "| 2 |", + "| 0 |", + "| 0 |", + "| 0 |", + "+--------------------------------------+", ]; assert_batches_eq!(expected, &actual); Ok(()) diff --git a/datafusion/core/tests/sql/select.rs b/datafusion/core/tests/sql/select.rs index fc1eee2af4c3..41554ab3c70e 100644 --- a/datafusion/core/tests/sql/select.rs +++ b/datafusion/core/tests/sql/select.rs @@ -478,14 +478,14 @@ async fn use_between_expression_in_select_query() -> Result<()> { let actual = execute_to_batches(&ctx, sql).await; // Expect field name to be correctly converted for expr, low and high. let expected = vec![ - "+--------------------------------------------------------------------+", - "| abs(test.c1) BETWEEN Int64(0) AND log(test.c1 Multiply Int64(100)) |", - "+--------------------------------------------------------------------+", - "| true |", - "| true |", - "| false |", - "| false |", - "+--------------------------------------------------------------------+", + "+-------------------------------------------------------------+", + "| abs(test.c1) BETWEEN Int64(0) AND log(test.c1 * Int64(100)) |", + "+-------------------------------------------------------------+", + "| true |", + "| true |", + "| false |", + "| false |", + "+-------------------------------------------------------------+", ]; assert_batches_eq!(expected, &actual); @@ -1204,11 +1204,11 @@ async fn unprojected_filter() { let results = df.collect().await.unwrap(); let expected = vec![ - "+--------------------------+", - "| ?table?.i Plus ?table?.i |", - "+--------------------------+", - "| 6 |", - "+--------------------------+", + "+-----------------------+", + "| ?table?.i + ?table?.i |", + "+-----------------------+", + "| 6 |", + "+-----------------------+", ]; assert_batches_sorted_eq!(expected, &results); } diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index 351f8a5e3c6a..dae0e74c4946 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -564,19 +564,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+---------------------+-------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+---------------------+-------------------------+--------------------------+", - "| 2020-09-08 13:42:29 | 2020-09-08 13:42:29.190 | true |", - "| 2020-09-08 13:42:29 | 2020-09-08 12:42:29.190 | false |", - "| 2020-09-08 13:42:29 | 2020-09-08 11:42:29.190 | false |", - "| 2020-09-08 12:42:29 | 2020-09-08 13:42:29.190 | false |", - "| 2020-09-08 12:42:29 | 2020-09-08 12:42:29.190 | true |", - "| 2020-09-08 12:42:29 | 2020-09-08 11:42:29.190 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 13:42:29.190 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 12:42:29.190 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 11:42:29.190 | true |", - "+---------------------+-------------------------+--------------------------+", + "+---------------------+-------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+---------------------+-------------------------+-------------------------+", + "| 2020-09-08 13:42:29 | 2020-09-08 13:42:29.190 | true |", + "| 2020-09-08 13:42:29 | 2020-09-08 12:42:29.190 | false |", + "| 2020-09-08 13:42:29 | 2020-09-08 11:42:29.190 | false |", + "| 2020-09-08 12:42:29 | 2020-09-08 13:42:29.190 | false |", + "| 2020-09-08 12:42:29 | 2020-09-08 12:42:29.190 | true |", + "| 2020-09-08 12:42:29 | 2020-09-08 11:42:29.190 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 13:42:29.190 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 12:42:29.190 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 11:42:29.190 | true |", + "+---------------------+-------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -591,19 +591,20 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+---------------------+----------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+---------------------+----------------------------+--------------------------+", - "| 2020-09-08 13:42:29 | 2020-09-08 13:42:29.190855 | true |", - "| 2020-09-08 13:42:29 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 13:42:29 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 12:42:29 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 12:42:29 | 2020-09-08 12:42:29.190855 | true |", - "| 2020-09-08 12:42:29 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 11:42:29.190855 | true |", - "+---------------------+----------------------------+--------------------------+", + "+---------------------+----------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+---------------------+----------------------------+-------------------------+", + "| 2020-09-08 13:42:29 | 2020-09-08 13:42:29.190855 | true |", + "| 2020-09-08 13:42:29 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 13:42:29 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 12:42:29 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 12:42:29 | 2020-09-08 12:42:29.190855 | true |", + "| 2020-09-08 12:42:29 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 11:42:29.190855 | true |", + "+---------------------+----------------------------+-------------------------+", + ]; assert_batches_eq!(expected, &actual); } @@ -618,19 +619,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+---------------------+----------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+---------------------+----------------------------+--------------------------+", - "| 2020-09-08 13:42:29 | 2020-09-08 13:42:29.190855 | true |", - "| 2020-09-08 13:42:29 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 13:42:29 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 12:42:29 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 12:42:29 | 2020-09-08 12:42:29.190855 | true |", - "| 2020-09-08 12:42:29 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 11:42:29 | 2020-09-08 11:42:29.190855 | true |", - "+---------------------+----------------------------+--------------------------+", + "+---------------------+----------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+---------------------+----------------------------+-------------------------+", + "| 2020-09-08 13:42:29 | 2020-09-08 13:42:29.190855 | true |", + "| 2020-09-08 13:42:29 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 13:42:29 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 12:42:29 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 12:42:29 | 2020-09-08 12:42:29.190855 | true |", + "| 2020-09-08 12:42:29 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 11:42:29 | 2020-09-08 11:42:29.190855 | true |", + "+---------------------+----------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -645,19 +646,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+-------------------------+---------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+-------------------------+---------------------+--------------------------+", - "| 2020-09-08 13:42:29.190 | 2020-09-08 13:42:29 | true |", - "| 2020-09-08 13:42:29.190 | 2020-09-08 12:42:29 | false |", - "| 2020-09-08 13:42:29.190 | 2020-09-08 11:42:29 | false |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 13:42:29 | false |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 12:42:29 | true |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 11:42:29 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 13:42:29 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 12:42:29 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 11:42:29 | true |", - "+-------------------------+---------------------+--------------------------+", + "+-------------------------+---------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+-------------------------+---------------------+-------------------------+", + "| 2020-09-08 13:42:29.190 | 2020-09-08 13:42:29 | true |", + "| 2020-09-08 13:42:29.190 | 2020-09-08 12:42:29 | false |", + "| 2020-09-08 13:42:29.190 | 2020-09-08 11:42:29 | false |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 13:42:29 | false |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 12:42:29 | true |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 11:42:29 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 13:42:29 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 12:42:29 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 11:42:29 | true |", + "+-------------------------+---------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -672,19 +673,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+-------------------------+----------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+-------------------------+----------------------------+--------------------------+", - "| 2020-09-08 13:42:29.190 | 2020-09-08 13:42:29.190855 | true |", - "| 2020-09-08 13:42:29.190 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 13:42:29.190 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 12:42:29.190855 | true |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 11:42:29.190855 | true |", - "+-------------------------+----------------------------+--------------------------+", + "+-------------------------+----------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+-------------------------+----------------------------+-------------------------+", + "| 2020-09-08 13:42:29.190 | 2020-09-08 13:42:29.190855 | true |", + "| 2020-09-08 13:42:29.190 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 13:42:29.190 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 12:42:29.190855 | true |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 11:42:29.190855 | true |", + "+-------------------------+----------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -699,19 +700,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+-------------------------+----------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+-------------------------+----------------------------+--------------------------+", - "| 2020-09-08 13:42:29.190 | 2020-09-08 13:42:29.190855 | true |", - "| 2020-09-08 13:42:29.190 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 13:42:29.190 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 12:42:29.190855 | true |", - "| 2020-09-08 12:42:29.190 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190 | 2020-09-08 11:42:29.190855 | true |", - "+-------------------------+----------------------------+--------------------------+", + "+-------------------------+----------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+-------------------------+----------------------------+-------------------------+", + "| 2020-09-08 13:42:29.190 | 2020-09-08 13:42:29.190855 | true |", + "| 2020-09-08 13:42:29.190 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 13:42:29.190 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 12:42:29.190855 | true |", + "| 2020-09-08 12:42:29.190 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190 | 2020-09-08 11:42:29.190855 | true |", + "+-------------------------+----------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -726,19 +727,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+---------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+----------------------------+---------------------+--------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29 | true |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29 | false |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29 | true |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29 | true |", - "+----------------------------+---------------------+--------------------------+", + "+----------------------------+---------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+----------------------------+---------------------+-------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29 | true |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29 | false |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29 | true |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29 | true |", + "+----------------------------+---------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -753,19 +754,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+-------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+----------------------------+-------------------------+--------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190 | true |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190 | false |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190 | true |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190 | true |", - "+----------------------------+-------------------------+--------------------------+", + "+----------------------------+-------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+----------------------------+-------------------------+-------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190 | true |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190 | false |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190 | true |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190 | true |", + "+----------------------------+-------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -780,19 +781,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+----------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+----------------------------+----------------------------+--------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190855 | true |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190855 | true |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190855 | true |", - "+----------------------------+----------------------------+--------------------------+", + "+----------------------------+----------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+----------------------------+----------------------------+-------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190855 | true |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190855 | true |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190855 | true |", + "+----------------------------+----------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -807,19 +808,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+---------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+----------------------------+---------------------+--------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29 | true |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29 | false |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29 | true |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29 | true |", - "+----------------------------+---------------------+--------------------------+", + "+----------------------------+---------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+----------------------------+---------------------+-------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29 | true |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29 | false |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29 | true |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29 | true |", + "+----------------------------+---------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -834,19 +835,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+-------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+----------------------------+-------------------------+--------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190 | true |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190 | false |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190 | true |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190 | true |", - "+----------------------------+-------------------------+--------------------------+", + "+----------------------------+-------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+----------------------------+-------------------------+-------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190 | true |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190 | false |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190 | true |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190 | true |", + "+----------------------------+-------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -861,19 +862,19 @@ async fn timestamp_coercion() -> Result<()> { let sql = "SELECT table_a.ts, table_b.ts, table_a.ts = table_b.ts FROM table_a, table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+----------------------------+--------------------------+", - "| ts | ts | table_a.ts Eq table_b.ts |", - "+----------------------------+----------------------------+--------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190855 | true |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190855 | true |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190855 | true |", - "+----------------------------+----------------------------+--------------------------+", + "+----------------------------+----------------------------+-------------------------+", + "| ts | ts | table_a.ts = table_b.ts |", + "+----------------------------+----------------------------+-------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.190855 | true |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.190855 | true |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 11:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 13:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 12:42:29.190855 | false |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.190855 | true |", + "+----------------------------+----------------------------+-------------------------+", ]; assert_batches_eq!(expected, &actual); } @@ -1446,52 +1447,52 @@ async fn timestamp_array_add_interval() -> Result<()> { let sql = "SELECT ts, ts - INTERVAL '8' MILLISECONDS FROM table_a"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+---------------------------------------+", - "| ts | table_a.ts Minus IntervalDayTime(\"8\") |", - "+----------------------------+---------------------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.182855 |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.182855 |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.182855 |", - "+----------------------------+---------------------------------------+", + "+----------------------------+-----------------------------------+", + "| ts | table_a.ts - IntervalDayTime(\"8\") |", + "+----------------------------+-----------------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:29.182855 |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:29.182855 |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:29.182855 |", + "+----------------------------+-----------------------------------+", ]; assert_batches_eq!(expected, &actual); let sql = "SELECT ts, ts + INTERVAL '1' SECOND FROM table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+-----------------------------------------+", - "| ts | table_b.ts Plus IntervalDayTime(\"1000\") |", - "+----------------------------+-----------------------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:30.190855 |", - "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:30.190855 |", - "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:30.190855 |", - "+----------------------------+-----------------------------------------+", + "+----------------------------+--------------------------------------+", + "| ts | table_b.ts + IntervalDayTime(\"1000\") |", + "+----------------------------+--------------------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-09-08 13:42:30.190855 |", + "| 2020-09-08 12:42:29.190855 | 2020-09-08 12:42:30.190855 |", + "| 2020-09-08 11:42:29.190855 | 2020-09-08 11:42:30.190855 |", + "+----------------------------+--------------------------------------+", ]; assert_batches_eq!(expected, &actual); let sql = "SELECT ts, ts + INTERVAL '2' MONTH FROM table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+----------------------------------------+", - "| ts | table_b.ts Plus IntervalYearMonth(\"2\") |", - "+----------------------------+----------------------------------------+", - "| 2020-09-08 13:42:29.190855 | 2020-11-08 13:42:29.190855 |", - "| 2020-09-08 12:42:29.190855 | 2020-11-08 12:42:29.190855 |", - "| 2020-09-08 11:42:29.190855 | 2020-11-08 11:42:29.190855 |", - "+----------------------------+----------------------------------------+", + "+----------------------------+-------------------------------------+", + "| ts | table_b.ts + IntervalYearMonth(\"2\") |", + "+----------------------------+-------------------------------------+", + "| 2020-09-08 13:42:29.190855 | 2020-11-08 13:42:29.190855 |", + "| 2020-09-08 12:42:29.190855 | 2020-11-08 12:42:29.190855 |", + "| 2020-09-08 11:42:29.190855 | 2020-11-08 11:42:29.190855 |", + "+----------------------------+-------------------------------------+", ]; assert_batches_eq!(expected, &actual); let sql = "SELECT ts, ts - INTERVAL '16' YEAR FROM table_b"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+----------------------------+-------------------------------------------+", - "| ts | table_b.ts Minus IntervalYearMonth(\"192\") |", - "+----------------------------+-------------------------------------------+", - "| 2020-09-08 13:42:29.190855 | 2004-09-08 13:42:29.190855 |", - "| 2020-09-08 12:42:29.190855 | 2004-09-08 12:42:29.190855 |", - "| 2020-09-08 11:42:29.190855 | 2004-09-08 11:42:29.190855 |", - "+----------------------------+-------------------------------------------+", + "+----------------------------+---------------------------------------+", + "| ts | table_b.ts - IntervalYearMonth(\"192\") |", + "+----------------------------+---------------------------------------+", + "| 2020-09-08 13:42:29.190855 | 2004-09-08 13:42:29.190855 |", + "| 2020-09-08 12:42:29.190855 | 2004-09-08 12:42:29.190855 |", + "| 2020-09-08 11:42:29.190855 | 2004-09-08 11:42:29.190855 |", + "+----------------------------+---------------------------------------+", ]; assert_batches_eq!(expected, &actual); Ok(()) diff --git a/datafusion/core/tests/sql/window.rs b/datafusion/core/tests/sql/window.rs index baaaee34314c..1c909fa71288 100644 --- a/datafusion/core/tests/sql/window.rs +++ b/datafusion/core/tests/sql/window.rs @@ -440,12 +440,12 @@ async fn window_in_expression() -> Result<()> { let sql = "select 1 - lag(amount, 1) over (order by idx) from (values ('a', 1, 100), ('a', 2, 150)) as t (col1, idx, amount)"; let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ - "+------------------------------------------------------------------------+", - "| Int64(1) Minus LAG(t.amount,Int64(1)) ORDER BY [#t.idx ASC NULLS LAST] |", - "+------------------------------------------------------------------------+", - "| |", - "| -99 |", - "+------------------------------------------------------------------------+", + "+--------------------------------------------------------------------+", + "| Int64(1) - LAG(t.amount,Int64(1)) ORDER BY [#t.idx ASC NULLS LAST] |", + "+--------------------------------------------------------------------+", + "| |", + "| -99 |", + "+--------------------------------------------------------------------+", ]; assert_batches_eq!(expected, &actual); Ok(()) From baf3016cef80d76b48fedb1089a1eec7abcf0b92 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Thu, 1 Sep 2022 08:58:03 -0600 Subject: [PATCH 4/4] Revert cast change --- datafusion/core/src/physical_plan/planner.rs | 12 +++--- datafusion/core/tests/dataframe_functions.rs | 16 +++---- datafusion/core/tests/sql/aggregates.rs | 10 ++--- datafusion/core/tests/sql/functions.rs | 44 ++++++++++---------- datafusion/core/tests/sql/parquet.rs | 24 +++++------ 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/datafusion/core/src/physical_plan/planner.rs b/datafusion/core/src/physical_plan/planner.rs index 1a165b1ce0e7..577e76a92927 100644 --- a/datafusion/core/src/physical_plan/planner.rs +++ b/datafusion/core/src/physical_plan/planner.rs @@ -128,13 +128,13 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result { 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)?; diff --git a/datafusion/core/tests/dataframe_functions.rs b/datafusion/core/tests/dataframe_functions.rs index 0d3631b18a70..19694285cc31 100644 --- a/datafusion/core/tests/dataframe_functions.rs +++ b/datafusion/core/tests/dataframe_functions.rs @@ -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); diff --git a/datafusion/core/tests/sql/aggregates.rs b/datafusion/core/tests/sql/aggregates.rs index deabe5c12eda..7e0e785da805 100644 --- a/datafusion/core/tests/sql/aggregates.rs +++ b/datafusion/core/tests/sql/aggregates.rs @@ -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); } diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs index a1594393cc21..e7bcb24c744d 100644 --- a/datafusion/core/tests/sql/functions.rs +++ b/datafusion/core/tests/sql/functions.rs @@ -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(()) diff --git a/datafusion/core/tests/sql/parquet.rs b/datafusion/core/tests/sql/parquet.rs index 8bec4f1dd3db..51304f60876c 100644 --- a/datafusion/core/tests/sql/parquet.rs +++ b/datafusion/core/tests/sql/parquet.rs @@ -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);