Skip to content

Commit 45f3ca1

Browse files
committed
fix(expr): fix common_super_type() for decimal
1 parent 07c7944 commit 45f3ca1

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/query/expression/src/type_check.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,10 @@ pub fn can_auto_cast_to(
516516
.zip(dest_tys)
517517
.all(|(src_ty, dest_ty)| can_auto_cast_to(src_ty, dest_ty, auto_cast_rules))
518518
}
519-
(DataType::Number(n), DataType::Decimal(_)) if !n.is_float() => true,
520519
(DataType::String, DataType::Decimal(_)) => true,
521520
(DataType::Decimal(x), DataType::Decimal(y)) => x.precision() <= y.precision(),
522-
(DataType::Decimal(_), DataType::Number(NumberDataType::Float32)) => true,
523-
(DataType::Decimal(_), DataType::Number(NumberDataType::Float64)) => true,
521+
(DataType::Number(n), DataType::Decimal(_)) if !n.is_float() => true,
522+
(DataType::Decimal(_), DataType::Number(n)) if n.is_float() => true,
524523
_ => false,
525524
}
526525
}
@@ -559,24 +558,24 @@ pub fn common_super_type(
559558
.collect::<Option<Vec<_>>>()?;
560559
Some(DataType::Tuple(tys))
561560
}
562-
(DataType::Number(_), DataType::Decimal(ty))
563-
| (DataType::Decimal(ty), DataType::Number(_)) => {
564-
let max_precision = ty.max_precision();
565-
let scale = ty.scale();
566-
567-
DecimalDataType::from_size(DecimalSize {
568-
precision: max_precision,
569-
scale,
570-
})
571-
.ok()
572-
.map(DataType::Decimal)
573-
}
574-
561+
(DataType::String, decimal_ty @ DataType::Decimal(_))
562+
| (decimal_ty @ DataType::Decimal(_), DataType::String) => Some(decimal_ty),
575563
(DataType::Decimal(a), DataType::Decimal(b)) => {
576564
let ty = DecimalDataType::binary_result_type(&a, &b, false, false, true).ok();
577565
ty.map(DataType::Decimal)
578566
}
579-
567+
(DataType::Number(num_ty), decimal_ty @ DataType::Decimal(_))
568+
| (decimal_ty @ DataType::Decimal(_), DataType::Number(num_ty))
569+
if !num_ty.is_float() =>
570+
{
571+
Some(decimal_ty)
572+
}
573+
(DataType::Number(num_ty), DataType::Decimal(_))
574+
| (DataType::Decimal(_), DataType::Number(num_ty))
575+
if num_ty.is_float() =>
576+
{
577+
Some(DataType::Number(num_ty))
578+
}
580579
(ty1, ty2) => {
581580
let ty1_can_cast_to = auto_cast_rules
582581
.iter()

0 commit comments

Comments
 (0)