Skip to content

Commit

Permalink
safer and test
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed May 5, 2024
1 parent 6ef8d0e commit fccc571
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ pub fn invoke<C: FromIterator<Option<I>> + 'static, I>(
to_array: impl Fn(C) -> DataFusionResult<ArrayRef>,
to_scalar: impl Fn(Option<I>) -> ScalarValue,
) -> DataFusionResult<ColumnarValue> {
match &args[0] {
let Some(first_arg) = args.first() else {
// I think this can't happen, but I assumed the same about args[1] and I was wrong, so better to be safe
return exec_err!("expected at least one argument");
};
match first_arg {
ColumnarValue::Array(json_array) => {
let result_collect = match args.get(1) {
Some(ColumnarValue::Array(a)) => {
Expand Down
8 changes: 8 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,11 @@ async fn test_json_length_vec() {
let batches = run_query_large(sql).await.unwrap();
assert_batches_eq!(expected, &batches);
}

#[tokio::test]
async fn test_no_args() {
let err = run_query(r#"select json_len()"#).await.unwrap_err();
assert!(err
.to_string()
.contains("No function matches the given name and argument types 'json_length()'."));
}

0 comments on commit fccc571

Please sign in to comment.