Skip to content

Commit

Permalink
fix(expr): cast int16/int32/int64/float32 to float64 in floor/ceil/ro…
Browse files Browse the repository at this point in the history
…und (#3319)

* fix(expr): cast int16/int32/int64/float32 to float64 in floor/ceil/round

* fix plan

Co-authored-by: TennyZhuang <[email protected]>
  • Loading branch information
name1e5s and TennyZhuang authored Jun 21, 2022
1 parent 964bb92 commit 16ffd98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,25 @@ impl Binder {
/// - round(Decimal, Int32) -> Decimal
/// - round(Decimal) -> Decimal
/// - round(Float64) -> Float64
/// - Extend: round(Int16, Int32, Int64, Float32) -> Decimal
/// - Extend: round(Int16, Int32, Int64, Float32) -> Float64
///
/// Ceil:
/// - ceil(Decimal) -> Decimal
/// - ceil(Float) -> Float64
/// - Extend: ceil(Int16, Int32, Int64, Float32) -> Decimal
/// - Extend: ceil(Int16, Int32, Int64, Float32) -> Float64
///
/// Floor:
/// - floor(Decimal) -> Decimal
/// - floor(Float) -> Float64
/// - Extend: floor(Int16, Int32, Int64, Float32) -> Decimal
/// - Extend: floor(Int16, Int32, Int64, Float32) -> Float64
fn rewrite_round_args(mut inputs: Vec<ExprImpl>) -> Vec<ExprImpl> {
if inputs.len() == 1 {
let input = inputs.pop().unwrap();
match input.return_type() {
risingwave_common::types::DataType::Float64 => vec![input],
risingwave_common::types::DataType::Decimal => vec![input],
_ => vec![input
.clone()
.cast_implicit(DataType::Decimal)
.cast_implicit(DataType::Float64)
.unwrap_or(input)],
}
} else if inputs.len() == 2 {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/test_runner/tests/testdata/expr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
- sql: |
values(round(42));
batch_plan: |
BatchValues { rows: [[Round(42:Int32::Decimal)]] }
BatchValues { rows: [[Round(42:Int32::Float64)]] }
- sql: |
values(round(42, 2));
batch_plan: |
Expand Down

0 comments on commit 16ffd98

Please sign in to comment.