Skip to content

Commit fe6190b

Browse files
authored
Support type-coercion from Decimal to Float64 (#2396)
1 parent 98ce80f commit fe6190b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

datafusion/core/tests/sql/decimal.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,3 +780,34 @@ async fn decimal_group_function() -> Result<()> {
780780
assert_batches_eq!(expected, &actual);
781781
Ok(())
782782
}
783+
784+
#[tokio::test]
785+
async fn sql_abs_decimal() -> Result<()> {
786+
let ctx = SessionContext::new();
787+
register_decimal_csv_table_by_sql(&ctx).await;
788+
let sql = "SELECT abs(c1) from decimal_simple";
789+
let actual = execute_to_batches(&ctx, sql).await;
790+
let expected = vec![
791+
"+------------------------+",
792+
"| abs(decimal_simple.c1) |",
793+
"+------------------------+",
794+
"| 0.00001 |",
795+
"| 0.00002 |",
796+
"| 0.00002 |",
797+
"| 0.00003 |",
798+
"| 0.00003 |",
799+
"| 0.00003 |",
800+
"| 0.00004 |",
801+
"| 0.00004 |",
802+
"| 0.00004 |",
803+
"| 0.00004 |",
804+
"| 0.00005 |",
805+
"| 0.00005 |",
806+
"| 0.00005 |",
807+
"| 0.00005 |",
808+
"| 0.00005 |",
809+
"+------------------------+",
810+
];
811+
assert_batches_eq!(expected, &actual);
812+
Ok(())
813+
}

datafusion/expr/src/type_coercion.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ pub fn can_coerce_from(type_into: &DataType, type_from: &DataType) -> bool {
169169
| UInt64
170170
| Float32
171171
| Float64
172+
| Decimal(_, _)
172173
),
173174
Timestamp(TimeUnit::Nanosecond, None) => matches!(type_from, Timestamp(_, None)),
174175
Utf8 | LargeUtf8 => true,

0 commit comments

Comments
 (0)