Skip to content

Commit 4bcf8af

Browse files
authored
Show unexpected type in error (#10)
1 parent ebb8c0b commit 4bcf8af

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ pub fn check_args(args: &[DataType], fn_name: &str) -> DataFusionResult<()> {
1111
return plan_err!("The '{fn_name}' function requires one or more arguments.");
1212
};
1313
if !matches!(first, DataType::Utf8 | DataType::LargeUtf8) {
14-
return plan_err!("Unexpected argument type to '{fn_name}' at position 1, expected a string.");
14+
return plan_err!("Unexpected argument type to '{fn_name}' at position 1, expected a string, got {first:?}.");
1515
}
1616
args[1..].iter().enumerate().try_for_each(|(index, arg)| match arg {
1717
DataType::Utf8 | DataType::LargeUtf8 | DataType::UInt64 | DataType::Int64 => Ok(()),
18-
_ => plan_err!(
19-
"Unexpected argument type to '{fn_name}' at position {}, expected string or int.",
18+
t => plan_err!(
19+
"Unexpected argument type to '{fn_name}' at position {}, expected string or int, got {t:?}.",
2020
index + 2
2121
),
2222
})

tests/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ async fn test_json_get_str_null() {
185185

186186
assert_eq!(
187187
e.to_string(),
188-
"Error during planning: Unexpected argument type to 'json_get_str' at position 2, expected string or int."
188+
"Error during planning: Unexpected argument type to 'json_get_str' at position 2, expected string or int, got Null."
189189
);
190190
}
191191

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

210+
#[tokio::test]
211+
async fn test_json_get_path() {
212+
let batches = run_query(r#"select json_get('{"i": 19}', 'i')::int<20"#).await.unwrap();
213+
assert_eq!(display_val(batches).await, (DataType::Boolean, "true".to_string()));
214+
}
215+
210216
#[tokio::test]
211217
async fn test_json_get_cast_int() {
212218
let sql = r#"select json_get('{"foo": 42}', 'foo')::int"#;

0 commit comments

Comments
 (0)