Skip to content

Commit

Permalink
show unexpected tyep in error
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed May 6, 2024
1 parent ebb8c0b commit 9d28e82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ pub fn check_args(args: &[DataType], fn_name: &str) -> DataFusionResult<()> {
return plan_err!("The '{fn_name}' function requires one or more arguments.");
};
if !matches!(first, DataType::Utf8 | DataType::LargeUtf8) {
return plan_err!("Unexpected argument type to '{fn_name}' at position 1, expected a string.");
return plan_err!("Unexpected argument type to '{fn_name}' at position 1, expected a string, got {first:?}.");
}
args[1..].iter().enumerate().try_for_each(|(index, arg)| match arg {
DataType::Utf8 | DataType::LargeUtf8 | DataType::UInt64 | DataType::Int64 => Ok(()),
_ => plan_err!(
"Unexpected argument type to '{fn_name}' at position {}, expected string or int.",
t => plan_err!(
"Unexpected argument type to '{fn_name}' at position {}, expected string or int, got {t:?}.",
index + 2
),
})
Expand Down
8 changes: 7 additions & 1 deletion tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async fn test_json_get_str_null() {

assert_eq!(
e.to_string(),
"Error during planning: Unexpected argument type to 'json_get_str' at position 2, expected string or int."
"Error during planning: Unexpected argument type to 'json_get_str' at position 2, expected string or int, got Null."
);
}

Expand All @@ -207,6 +207,12 @@ async fn test_json_get_int() {
assert_eq!(display_val(batches).await, (DataType::Int64, "2".to_string()));
}

#[tokio::test]
async fn test_json_get_path() {
let batches = run_query(r#"select json_get('{"i": 19}', 'i')::int<20"#).await.unwrap();
assert_eq!(display_val(batches).await, (DataType::Boolean, "true".to_string()));
}

#[tokio::test]
async fn test_json_get_cast_int() {
let sql = r#"select json_get('{"foo": 42}', 'foo')::int"#;
Expand Down

0 comments on commit 9d28e82

Please sign in to comment.