Skip to content

Commit ef0b58e

Browse files
authored
fix(bind): disable the shrink constant when it is a generic type argument of a function (#18145)
disable the shrink constant when it is a generic type argument of a function
1 parent e58eeeb commit ef0b58e

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/query/expression/src/utils/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::types::decimal::MAX_DECIMAL256_PRECISION;
3535
use crate::types::i256;
3636
use crate::types::AnyType;
3737
use crate::types::DataType;
38+
use crate::types::Decimal;
3839
use crate::types::DecimalDataKind;
3940
use crate::types::DecimalSize;
4041
use crate::types::NumberScalar;
@@ -180,7 +181,7 @@ fn shrink_d256(decimal: i256, size: DecimalSize) -> Scalar {
180181
let log10_2 = std::f64::consts::LOG10_2;
181182
let mut precision = ((valid_bits as f64) * log10_2).floor() as u8;
182183

183-
if decimal.saturating_abs() >= i256::from(10).pow(precision as u32) {
184+
if decimal.saturating_abs() >= i256::e(precision) {
184185
precision += 1;
185186
}
186187

src/query/sql/src/planner/semantic/type_check.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,21 +3032,25 @@ impl<'a> TypeChecker<'a> {
30323032

30333033
let mut folded_args = match &expr {
30343034
expr::Expr::FunctionCall(expr::FunctionCall {
3035-
args: checked_args, ..
3036-
}) => {
3037-
let mut folded_args = Vec::with_capacity(args.len());
3038-
for (checked_arg, arg) in checked_args.iter().zip(args.iter()) {
3039-
match self.try_fold_constant(checked_arg, true) {
3040-
Some(constant) if arg.evaluable() => {
3041-
folded_args.push(constant.0);
3042-
}
3043-
_ => {
3044-
folded_args.push(arg.clone());
3045-
}
3046-
}
3047-
}
3048-
folded_args
3049-
}
3035+
function,
3036+
args: checked_args,
3037+
..
3038+
}) => checked_args
3039+
.iter()
3040+
.zip(
3041+
function
3042+
.signature
3043+
.args_type
3044+
.iter()
3045+
.map(DataType::is_generic),
3046+
)
3047+
.map(|(checked_arg, is_generic)| self.try_fold_constant(checked_arg, !is_generic))
3048+
.zip(args)
3049+
.map(|(folded, arg)| match folded {
3050+
Some(box (constant, _)) if arg.evaluable() => constant,
3051+
_ => arg,
3052+
})
3053+
.collect(),
30503054
_ => args,
30513055
};
30523056

tests/sqllogictests/suites/query/functions/02_0058_function_ifnull.test

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ NULL 0 0
8787
NULL 1 1
8888
NULL NULL NULL
8989

90+
query R
91+
select ifnull(number::string, 0) from numbers(3);
92+
----
93+
0.00000
94+
1.00000
95+
2.00000
96+
9097
statement ok
9198
DROP TABLE t
92-

0 commit comments

Comments
 (0)