Skip to content

Commit 14b24bc

Browse files
authored
fix(query): decimal64 not correct shrink_scalar (#18267)
fix
1 parent 3840805 commit 14b24bc

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub fn shrink_scalar(scalar: Scalar) -> Scalar {
134134
Scalar::Number(NumberScalar::Int16(n)) => shrink_i64(n as i64),
135135
Scalar::Number(NumberScalar::Int32(n)) => shrink_i64(n as i64),
136136
Scalar::Number(NumberScalar::Int64(n)) => shrink_i64(n),
137+
Scalar::Decimal(DecimalScalar::Decimal64(d, size)) => shrink_d256(d.into(), size),
137138
Scalar::Decimal(DecimalScalar::Decimal128(d, size)) => shrink_d256(d.into(), size),
138139
Scalar::Decimal(DecimalScalar::Decimal256(d, size)) => shrink_d256(d, size),
139140
Scalar::Tuple(mut fields) => {
@@ -208,3 +209,35 @@ fn shrink_d256(decimal: i256, size: DecimalSize) -> Scalar {
208209
DecimalDataKind::Decimal256 => Scalar::Decimal(DecimalScalar::Decimal256(decimal, size)),
209210
}
210211
}
212+
213+
#[cfg(test)]
214+
mod tests {
215+
use super::*;
216+
217+
#[test]
218+
fn test_shrink_scalar() {
219+
let tests = [
220+
(
221+
Scalar::Decimal(DecimalScalar::Decimal64(
222+
50,
223+
DecimalSize::new_unchecked(10, 1),
224+
)),
225+
Scalar::Decimal(DecimalScalar::Decimal64(
226+
50,
227+
DecimalSize::new_unchecked(2, 1),
228+
)),
229+
),
230+
(
231+
Scalar::Decimal(DecimalScalar::Decimal64(
232+
50,
233+
DecimalSize::new_unchecked(10, 0),
234+
)),
235+
Scalar::Number(NumberScalar::UInt8(50)),
236+
),
237+
];
238+
239+
for (t, want) in tests {
240+
assert_eq!(shrink_scalar(t), want);
241+
}
242+
}
243+
}

src/query/functions/tests/it/scalars/arithmetic.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ use databend_common_expression::FromData;
2424
use goldenfile::Mint;
2525

2626
use super::run_ast;
27-
use super::run_ast_with_context;
28-
use super::TestContext;
2927

3028
#[test]
3129
fn test_arithmetic() {
@@ -312,17 +310,11 @@ fn test_decimal() {
312310
),
313311
];
314312

315-
run_ast_with_context(
313+
run_ast(
316314
file,
317315
"l_extendedprice + (1 - l_discount) - l_quantity",
318-
TestContext {
319-
columns: &columns,
320-
..Default::default()
321-
},
316+
&columns,
322317
);
323318

324-
run_ast_with_context(file, "1964831797.0000 - 0.0214642400000", TestContext {
325-
columns: &columns,
326-
..Default::default()
327-
})
319+
run_ast(file, "1964831797.0000 - 0.0214642400000", &columns);
328320
}

0 commit comments

Comments
 (0)