Apache DataFusion SQL Query Engine
Support type-coercion from Decimal to Float64 (#2396)
compheadfe6190b188f2
diff --git a/datafusion/core/tests/sql/decimal.rs b/datafusion/core/tests/sql/decimal.rsindex 2153495a62..c8c2421552 100644--- a/datafusion/core/tests/sql/decimal.rs+++ b/datafusion/core/tests/sql/decimal.rs@@ -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(())+}diff --git a/datafusion/expr/src/type_coercion.rs b/datafusion/expr/src/type_coercion.rsindex 5b8b303611..8cea256f18 100644--- a/datafusion/expr/src/type_coercion.rs+++ b/datafusion/expr/src/type_coercion.rs@@ -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,