Repository: databendlabs/databend (language: rust)

Issue:
bug: decimal value div cause panic
### Search before asking

- [x] I had searched in the [issues](https://github.com/databendlabs/databend/issues) and found no similar issues.


### Version

main

### What's Wrong?

decimal value div cause panic, should return out of range error.
this bug is found by Tidb test
```
panicked at src/query/expression/src/utils/mod.rs:190:55:
called `Result::unwrap()` on an `Err` value: Overflow. Code: 1049, Text = Decimal scale must be between 0 and precision 76.
```

### How to Reproduce?

```sql
root@0.0.0.0:48000/default> select 1e200/1e-200;
error: APIError: QueryFailed: [1104]called `Result::unwrap()` on an `Err` value: Overflow. Code: 1049, Text = Decimal scale must be between 0 and precision 76.
```

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!


Discussion / hints:

Fix patch:
diff --git a/src/query/ast/src/parser/expr.rs b/src/query/ast/src/parser/expr.rs
index 87d7a38dda8d..50e210332281 100644
--- a/src/query/ast/src/parser/expr.rs
+++ b/src/query/ast/src/parser/expr.rs
@@ -1977,7 +1977,9 @@ pub fn parse_float(text: &str) -> Result<Literal, ErrorKind> {
         },
         None => 0,
     };
-    if i_part.len() as i32 + exp > 76 {
+
+    let p = i_part.len() as i32 + exp - f_part.len() as i32;
+    if !(-76..=76).contains(&p) {
         Ok(Literal::Float64(fast_float2::parse(text)?))
     } else {
         let mut digits = String::with_capacity(76);
diff --git a/src/query/sql/src/planner/semantic/type_check.rs b/src/query/sql/src/planner/semantic/type_check.rs
index 7b531f4c667a..452d0255b0e5 100644
--- a/src/query/sql/src/planner/semantic/type_check.rs
+++ b/src/query/sql/src/planner/semantic/type_check.rs
@@ -1104,7 +1104,12 @@ impl<'a> TypeChecker<'a> {
 
             Expr::Tuple { span, exprs, .. } => self.resolve_tuple(*span, exprs)?,
 
-            Expr::Hole { .. } => unreachable!("hole is impossible in trivial query"),
+            Expr::Hole { span, .. } => {
+                return Err(ErrorCode::SemanticError(
+                    "Hole expression is impossible in trivial query".to_string(),
+                )
+                .set_span(*span))
+            }
         };
         Ok(Box::new((scalar, data_type)))
     }


Test patch:
diff --git a/tests/sqllogictests/suites/base/11_data_type/11_0006_data_type_decimal.test b/tests/sqllogictests/suites/base/11_data_type/11_0006_data_type_decimal.test
index 9ee425a0887d..df3ea852f0b0 100644
--- a/tests/sqllogictests/suites/base/11_data_type/11_0006_data_type_decimal.test
+++ b/tests/sqllogictests/suites/base/11_data_type/11_0006_data_type_decimal.test
@@ -270,6 +270,11 @@ select CAST(116214450.599999999999999 AS DECIMAL(38, 14)) *
 
 ## div
 
+query B
+SELECT 1e100/1e-100 = 1e200, 1e-100/1e-100 = 1, 1e-100/1e100 > 0;
+----
+1 1 1
+
 query I
 SELECT CAST(4.56 AS DECIMAL(6, 2)) / CAST(1.23 AS DECIMAL(6, 2)) AS result;
 ----