Skip to content

Commit e571d78

Browse files
andygrovemcheshkov
authored andcommitted
Add SQL planner support for calling round function with two arguments (apache#2503)
* test * specify correct signature for ROUND function Can drop this after rebase on commit 8a29ed5 "Add SQL planner support for calling round function with two arguments (apache#2503)", first released in 8.0.0 (cherry picked from commit 8a29ed5) # Conflicts: # datafusion/core/src/sql/planner.rs # datafusion/expr/src/function.rs
1 parent 755e4a6 commit e571d78

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

datafusion/core/src/sql/planner.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5052,6 +5052,10 @@ mod tests {
50525052
name: TableReference,
50535053
) -> Option<Arc<dyn TableProvider>> {
50545054
let schema = match name.table() {
5055+
"test_decimal" => Some(Schema::new(vec![
5056+
Field::new("id", DataType::Int32, false),
5057+
Field::new("price", DataType::Decimal(10, 2), false),
5058+
])),
50555059
"person" => Some(Schema::new(vec![
50565060
Field::new("id", DataType::UInt32, false),
50575061
Field::new("first_name", DataType::Utf8, false),
@@ -5443,6 +5447,14 @@ mod tests {
54435447
quick_test(sql, expected);
54445448
}
54455449

5450+
#[tokio::test]
5451+
async fn round_decimal() {
5452+
let sql = "SELECT round(price/3, 2) FROM test_decimal";
5453+
let expected = "Projection: round(#test_decimal.price / Int64(3), Int64(2))\
5454+
\n TableScan: test_decimal projection=None";
5455+
quick_test(sql, expected);
5456+
}
5457+
54465458
#[ignore] // see https://github.com/apache/arrow-datafusion/issues/2469
54475459
#[tokio::test]
54485460
async fn aggregate_with_grouping_sets() {

datafusion/expr/src/function.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature {
576576
),
577577
BuiltinScalarFunction::Round => Signature::one_of(
578578
vec![
579+
TypeSignature::Exact(vec![DataType::Float64, DataType::Int64]),
580+
TypeSignature::Exact(vec![DataType::Float32, DataType::Int64]),
579581
TypeSignature::Exact(vec![DataType::Float64]),
580582
TypeSignature::Exact(vec![DataType::Float32]),
581583
// NOTE: stub, won't execute

0 commit comments

Comments
 (0)