Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(expr): include data type in parse error message #13121

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/expr/impl/src/scalar/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ use risingwave_pb::expr::expr_node::PbType;
#[function("cast(varchar) -> timestamp")]
#[function("cast(varchar) -> interval")]
#[function("cast(varchar) -> jsonb")]
pub fn str_parse<T>(elem: &str) -> Result<T>
pub fn str_parse<T>(elem: &str, ctx: &Context) -> Result<T>
where
T: FromStr,
<T as FromStr>::Err: std::fmt::Display,
{
elem.trim()
.parse()
.map_err(|err: <T as FromStr>::Err| ExprError::Parse(err.to_string().into()))
elem.trim().parse().map_err(|err: <T as FromStr>::Err| {
ExprError::Parse(format!("{} {}", ctx.return_type, err).into())
})
}

// TODO: introduce `FromBinary` and support all types
Expand Down Expand Up @@ -521,7 +521,11 @@ mod tests {
async fn test_unary() {
test_unary_bool::<BoolArray, _>(|x| !x, PbType::Not).await;
test_unary_date::<TimestampArray, _>(|x| try_cast(x).unwrap(), PbType::Cast).await;
test_str_to_int16::<I16Array, _>(|x| str_parse(x).unwrap()).await;
let ctx_str_to_int16 = Context {
arg_types: vec![DataType::Varchar],
return_type: DataType::Int16,
};
test_str_to_int16::<I16Array, _>(|x| str_parse(x, &ctx_str_to_int16).unwrap()).await;
}

#[tokio::test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
- create_table_and_mv
sql: |
SELECT * FROM orders_count_by_user WHERE user_id = 'a'
batch_error: 'Expr error: Parse error: invalid digit found in string'
batch_error: 'Expr error: Parse error: bigint invalid digit found in string'
- before:
- create_table_and_mv
sql: |
SELECT * FROM orders_count_by_user WHERE user_id > 'a'
batch_error: 'Expr error: Parse error: invalid digit found in string'
batch_error: 'Expr error: Parse error: bigint invalid digit found in string'
- before:
- create_table_and_mv
sql: |
Expand Down Expand Up @@ -129,7 +129,7 @@
- create_table_and_mv
sql: |
SELECT * FROM orders_count_by_user WHERE user_id in ('42', '43.0')
batch_error: 'Expr error: Parse error: invalid digit found in string'
batch_error: 'Expr error: Parse error: bigint invalid digit found in string'
- before:
- create_table_and_mv
sql: |
Expand Down
Loading