Skip to content

Commit c990e9b

Browse files
authored
Merge pull request #10451 from andylokandy/fixx3
fix(expr): fix common_super_type() for decimal
2 parents f7fcd3e + 83c61a7 commit c990e9b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/query/expression/src/type_check.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,10 @@ pub fn can_auto_cast_to(
559559
.zip(dest_tys)
560560
.all(|(src_ty, dest_ty)| can_auto_cast_to(src_ty, dest_ty, auto_cast_rules))
561561
}
562-
(DataType::Number(n), DataType::Decimal(_)) if !n.is_float() => true,
563562
(DataType::String, DataType::Decimal(_)) => true,
564563
(DataType::Decimal(x), DataType::Decimal(y)) => x.precision() <= y.precision(),
565-
(DataType::Decimal(_), DataType::Number(NumberDataType::Float32)) => true,
566-
(DataType::Decimal(_), DataType::Number(NumberDataType::Float64)) => true,
564+
(DataType::Number(n), DataType::Decimal(_)) if !n.is_float() => true,
565+
(DataType::Decimal(_), DataType::Number(n)) if n.is_float() => true,
567566
_ => false,
568567
}
569568
}
@@ -602,24 +601,31 @@ pub fn common_super_type(
602601
.collect::<Option<Vec<_>>>()?;
603602
Some(DataType::Tuple(tys))
604603
}
605-
(DataType::Number(_), DataType::Decimal(ty))
606-
| (DataType::Decimal(ty), DataType::Number(_)) => {
607-
let max_precision = ty.max_precision();
608-
let scale = ty.scale();
609-
604+
(DataType::String, decimal_ty @ DataType::Decimal(_))
605+
| (decimal_ty @ DataType::Decimal(_), DataType::String) => Some(decimal_ty),
606+
(DataType::Decimal(a), DataType::Decimal(b)) => {
607+
let ty = DecimalDataType::binary_result_type(&a, &b, false, false, true).ok();
608+
ty.map(DataType::Decimal)
609+
}
610+
(DataType::Number(num_ty), DataType::Decimal(decimal_ty))
611+
| (DataType::Decimal(decimal_ty), DataType::Number(num_ty))
612+
if !num_ty.is_float() =>
613+
{
614+
let max_precision = decimal_ty.max_precision();
615+
let scale = decimal_ty.scale();
610616
DecimalDataType::from_size(DecimalSize {
611617
precision: max_precision,
612618
scale,
613619
})
614620
.ok()
615621
.map(DataType::Decimal)
616622
}
617-
618-
(DataType::Decimal(a), DataType::Decimal(b)) => {
619-
let ty = DecimalDataType::binary_result_type(&a, &b, false, false, true).ok();
620-
ty.map(DataType::Decimal)
623+
(DataType::Number(num_ty), DataType::Decimal(_))
624+
| (DataType::Decimal(_), DataType::Number(num_ty))
625+
if num_ty.is_float() =>
626+
{
627+
Some(DataType::Number(num_ty))
621628
}
622-
623629
(ty1, ty2) => {
624630
let ty1_can_cast_to = auto_cast_rules
625631
.iter()

0 commit comments

Comments
 (0)