Skip to content

Commit

Permalink
Revert cast change
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Sep 1, 2022
1 parent fe26486 commit baf3016
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
12 changes: 6 additions & 6 deletions datafusion/core/src/physical_plan/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
16 changes: 8 additions & 8 deletions datafusion/core/tests/dataframe_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions datafusion/core/tests/sql/aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
44 changes: 22 additions & 22 deletions datafusion/core/tests/sql/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down
24 changes: 12 additions & 12 deletions datafusion/core/tests/sql/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit baf3016

Please sign in to comment.