diff --git a/src/common.rs b/src/common.rs index 0df41a2..5804158 100644 --- a/src/common.rs +++ b/src/common.rs @@ -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 ), }) diff --git a/tests/main.rs b/tests/main.rs index 3531b77..83dbdd8 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -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." ); } @@ -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"#;