Skip to content

Commit 0d86d5a

Browse files
authored
fix(query): fix resolve decimal (#17409)
1 parent 77a9159 commit 0d86d5a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/query/ast/src/parser/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,9 @@ pub fn parse_float(text: &str) -> Result<Literal, ErrorKind> {
19771977
},
19781978
None => 0,
19791979
};
1980-
if i_part.len() as i32 + exp > 76 {
1980+
1981+
let p = i_part.len() as i32 + exp - f_part.len() as i32;
1982+
if !(-76..=76).contains(&p) {
19811983
Ok(Literal::Float64(fast_float2::parse(text)?))
19821984
} else {
19831985
let mut digits = String::with_capacity(76);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,12 @@ impl<'a> TypeChecker<'a> {
11041104

11051105
Expr::Tuple { span, exprs, .. } => self.resolve_tuple(*span, exprs)?,
11061106

1107-
Expr::Hole { .. } => unreachable!("hole is impossible in trivial query"),
1107+
Expr::Hole { span, .. } => {
1108+
return Err(ErrorCode::SemanticError(
1109+
"Hole expression is impossible in trivial query".to_string(),
1110+
)
1111+
.set_span(*span))
1112+
}
11081113
};
11091114
Ok(Box::new((scalar, data_type)))
11101115
}

tests/sqllogictests/suites/base/11_data_type/11_0006_data_type_decimal.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ select CAST(116214450.599999999999999 AS DECIMAL(38, 14)) *
270270

271271
## div
272272

273+
query B
274+
SELECT 1e100/1e-100 = 1e200, 1e-100/1e-100 = 1, 1e-100/1e100 > 0;
275+
----
276+
1 1 1
277+
273278
query I
274279
SELECT CAST(4.56 AS DECIMAL(6, 2)) / CAST(1.23 AS DECIMAL(6, 2)) AS result;
275280
----

0 commit comments

Comments
 (0)