Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Sep 12, 2024
1 parent 5a1bcfa commit 7e2788f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/query/expression/src/utils/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
// limitations under the License.

use std::cmp::Ordering;
use std::result::Result;

use chrono::Datelike;
use chrono::NaiveDate;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;

use crate::types::decimal::Decimal;
use crate::types::decimal::DecimalSize;
Expand All @@ -29,12 +28,13 @@ pub fn uniform_date(date: NaiveDate) -> i32 {
date.num_days_from_ce() - EPOCH_DAYS_FROM_CE
}

// Used in function, so we don't want to return ErrorCode with backtrace
pub fn read_decimal_with_size<T: Decimal>(
buf: &[u8],
size: DecimalSize,
exact: bool,
rounding_mode: bool,
) -> Result<(T, usize)> {
) -> Result<(T, usize), String> {
// Read one more digit for round
let (n, d, e, n_read) =
read_decimal::<T>(buf, (size.precision + 1) as u32, size.scale as _, exact)?;
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn read_decimal<T: Decimal>(
max_digits: u32,
mut max_scales: u32,
exact: bool,
) -> Result<(T, u8, i32, usize)> {
) -> Result<(T, u8, i32, usize), String> {
if buf.is_empty() {
return Err(decimal_parse_error("empty"));
}
Expand Down Expand Up @@ -302,7 +302,7 @@ pub fn read_decimal<T: Decimal>(
pub fn read_decimal_from_json<T: Decimal>(
value: &serde_json::Value,
size: DecimalSize,
) -> Result<T> {
) -> Result<T, String> {
match value {
serde_json::Value::Number(n) => {
if n.is_i64() {
Expand All @@ -323,14 +323,14 @@ pub fn read_decimal_from_json<T: Decimal>(
let (n, _) = read_decimal_with_size::<T>(s.as_bytes(), size, true, true)?;
Ok(n)
}
_ => Err(ErrorCode::from("Incorrect json value for decimal")),
_ => Err("Incorrect json value for decimal".to_string()),
}
}

fn decimal_parse_error(msg: &str) -> ErrorCode {
ErrorCode::BadArguments(format!("bad decimal literal: {msg}"))
fn decimal_parse_error(msg: &str) -> String {
format!("bad decimal literal: {msg}")
}

fn decimal_overflow_error() -> ErrorCode {
ErrorCode::Overflow("Decimal overflow")
fn decimal_overflow_error() -> String {
"Decimal overflow".to_string()
}
2 changes: 1 addition & 1 deletion src/query/functions/src/scalars/decimal/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ where
{
Ok((d, _)) => d,
Err(e) => {
ctx.set_error(builder.len(), e.message());
ctx.set_error(builder.len(), e);
T::zero()
}
};
Expand Down

0 comments on commit 7e2788f

Please sign in to comment.