Skip to content

Commit 1122e75

Browse files
authored
fix(function): the add and minus functions of decimal do not select the correct precision (#18161)
fix: The add and minus functions of decimal do not select the correct precision
1 parent d9767dc commit 1122e75

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

โ€Žsrc/query/functions/src/scalars/decimal/src/arithmetic.rsโ€Ž

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,9 @@ impl ArithmeticOp {
128128
))
129129
}
130130

131-
ArithmeticOp::Plus | ArithmeticOp::Minus => Some((
132-
if scale == a.scale() {
133-
*a
134-
} else {
135-
DecimalSize::new(a.precision(), scale).ok()?
136-
},
137-
if scale == b.scale() {
138-
*b
139-
} else {
140-
DecimalSize::new(b.precision(), scale).ok()?
141-
},
142-
result_type,
143-
)),
131+
ArithmeticOp::Plus | ArithmeticOp::Minus => {
132+
Some((result_type, result_type, result_type))
133+
}
144134
}
145135
}
146136
}

โ€Žsrc/query/functions/src/test_utils.rsโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::BUILTIN_FUNCTIONS;
4343

4444
pub fn parse_raw_expr(text: &str, columns: &[(&str, DataType)]) -> RawExpr {
4545
let tokens = tokenize_sql(text).unwrap();
46-
let expr = parse_expr(&tokens, Dialect::PostgreSQL).unwrap();
46+
let expr = parse_expr(&tokens, Dialect::PostgreSQL).expect("failed to parse expr");
4747
transform_expr(expr, columns)
4848
}
4949

โ€Žsrc/query/functions/tests/it/scalars/arithmetic.rsโ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,10 @@ fn test_decimal() {
319319
columns: &columns,
320320
..Default::default()
321321
},
322-
)
322+
);
323+
324+
run_ast_with_context(file, "1964831797.0000 - 0.0214642400000", TestContext {
325+
columns: &columns,
326+
..Default::default()
327+
})
323328
}

โ€Žsrc/query/functions/tests/it/scalars/testdata/arithmetic_decimal.txtโ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ evaluation (internal):
2929
+-----------------+------------------------------------------------------------------------------------------------------------------+
3030

3131

32+
ast : 1964831797.0000 - 0.0214642400000
33+
raw expr : minus(1964831797.0000, 0.0214642400000)
34+
checked expr : minus<Decimal(14, 4), Decimal(13, 13)>(1964831797.0000_d128(14,4), 0.0214642400000_d128(13,13))
35+
optimized expr : 1964831796.9785357600000_d128(24,13)
36+
output type : Decimal(24, 13)
37+
output domain : {1964831796.9785357600000..=1964831796.9785357600000}
38+
output : 1964831796.9785357600000
39+
40+

0 commit comments

Comments
ย (0)