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

Show unexpected type in error #10

Merged
merged 1 commit into from
May 6, 2024
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
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
Loading