Skip to content

Commit

Permalink
Support type-coercion from Decimal to Float64 (#2396)
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead authored May 1, 2022
1 parent 98ce80f commit fe6190b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions datafusion/core/tests/sql/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,3 +780,34 @@ async fn decimal_group_function() -> Result<()> {
assert_batches_eq!(expected, &actual);
Ok(())
}

#[tokio::test]
async fn sql_abs_decimal() -> Result<()> {
let ctx = SessionContext::new();
register_decimal_csv_table_by_sql(&ctx).await;
let sql = "SELECT abs(c1) from decimal_simple";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+------------------------+",
"| abs(decimal_simple.c1) |",
"+------------------------+",
"| 0.00001 |",
"| 0.00002 |",
"| 0.00002 |",
"| 0.00003 |",
"| 0.00003 |",
"| 0.00003 |",
"| 0.00004 |",
"| 0.00004 |",
"| 0.00004 |",
"| 0.00004 |",
"| 0.00005 |",
"| 0.00005 |",
"| 0.00005 |",
"| 0.00005 |",
"| 0.00005 |",
"+------------------------+",
];
assert_batches_eq!(expected, &actual);
Ok(())
}
1 change: 1 addition & 0 deletions datafusion/expr/src/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub fn can_coerce_from(type_into: &DataType, type_from: &DataType) -> bool {
| UInt64
| Float32
| Float64
| Decimal(_, _)
),
Timestamp(TimeUnit::Nanosecond, None) => matches!(type_from, Timestamp(_, None)),
Utf8 | LargeUtf8 => true,
Expand Down

0 comments on commit fe6190b

Please sign in to comment.