You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ag...@apache.org on 2022/05/01 00:26:27 UTC

[arrow-datafusion] branch master updated: Support type-coercion from Decimal to Float64 (#2396)

This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new fe6190b18 Support type-coercion from Decimal to Float64 (#2396)
fe6190b18 is described below

commit fe6190b188f2b7e88591480a2c9f6b847f71e79c
Author: comphead <co...@users.noreply.github.com>
AuthorDate: Sat Apr 30 17:26:23 2022 -0700

    Support type-coercion from Decimal to Float64 (#2396)
---
 datafusion/core/tests/sql/decimal.rs | 31 +++++++++++++++++++++++++++++++
 datafusion/expr/src/type_coercion.rs |  1 +
 2 files changed, 32 insertions(+)

diff --git a/datafusion/core/tests/sql/decimal.rs b/datafusion/core/tests/sql/decimal.rs
index 2153495a6..c8c242155 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.rs
index 5b8b30361..8cea256f1 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,