Skip to content

Commit 5a61d90

Browse files
committed
add test for return type in set_op.rs
1 parent f857c20 commit 5a61d90

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/functions-nested/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ paste = "1.0.14"
6161
[dev-dependencies]
6262
criterion = { workspace = true, features = ["async_tokio"] }
6363
rand = { workspace = true }
64+
rstest = { workspace = true }
6465

6566
[[bench]]
6667
harness = false

datafusion/functions-nested/src/set_ops.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,54 @@ fn general_array_distinct<OffsetSize: OffsetSizeTrait>(
555555
array.nulls().cloned(),
556556
)?))
557557
}
558+
559+
#[cfg(test)]
560+
mod tests {
561+
use rstest::*;
562+
use std::sync::Arc;
563+
564+
use arrow::{
565+
array::{Int32Array, ListArray},
566+
buffer::OffsetBuffer,
567+
datatypes::{DataType, Field},
568+
};
569+
use datafusion_common::{config::ConfigOptions, DataFusionError};
570+
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs};
571+
572+
use crate::set_ops::array_distinct_udf;
573+
574+
#[rstest(inner_nullable, case(true), case(false))]
575+
#[test]
576+
fn test_array_distinct_inner_nullability_result_type_match_return_type(
577+
inner_nullable: bool,
578+
) -> Result<(), DataFusionError> {
579+
let udf = array_distinct_udf();
580+
581+
let inner_field = Field::new_list_field(DataType::Int32, inner_nullable);
582+
let input_field = Field::new_list("input", Arc::new(inner_field.clone()), true);
583+
584+
// [[1, 1, 2]]
585+
let input_array = ListArray::new(
586+
inner_field.into(),
587+
OffsetBuffer::new(vec![0, 3].into()),
588+
Arc::new(Int32Array::new(vec![1, 1, 2].into(), None)),
589+
None,
590+
);
591+
let input_array = ColumnarValue::Array(Arc::new(input_array));
592+
593+
let result = udf.invoke_with_args(ScalarFunctionArgs {
594+
args: vec![input_array],
595+
arg_fields: vec![input_field.clone().into()],
596+
number_rows: 1,
597+
return_field: input_field.clone().into(),
598+
config_options: Arc::new(ConfigOptions::default()),
599+
})?;
600+
601+
assert_eq!(
602+
result.data_type(),
603+
udf.return_type(&[input_field.data_type().clone()])?
604+
);
605+
606+
Ok(())
607+
}
608+
}

0 commit comments

Comments
 (0)