MCPcopy Create free account
hub / github.com/apache/datafusion / nullif_struct

Function nullif_struct

datafusion/functions/src/core/nullif.rs:264–306  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

262
263 #[test]
264 fn nullif_struct() -> Result<()> {
265 let fields = Fields::from(vec![
266 Field::new("a", DataType::Int64, true),
267 Field::new("b", DataType::Utf8, true),
268 ]);
269
270 let lhs_a = Arc::new(Int64Array::from(vec![Some(1), Some(2), None]));
271 let lhs_b = Arc::new(StringArray::from(vec![Some("1"), Some("2"), None]));
272 let lhs_nulls = Some(NullBuffer::from(vec![true, true, false]));
273 let lhs = ColumnarValue::Array(Arc::new(StructArray::new(
274 fields.clone(),
275 vec![lhs_a, lhs_b],
276 lhs_nulls,
277 )));
278
279 let rhs_a = Arc::new(Int64Array::from(vec![Some(1), Some(9), None]));
280 let rhs_b = Arc::new(StringArray::from(vec![Some("1"), Some("2"), None]));
281 let rhs_nulls = Some(NullBuffer::from(vec![true, true, false]));
282 let rhs = ColumnarValue::Array(Arc::new(StructArray::new(
283 fields.clone(),
284 vec![rhs_a, rhs_b],
285 rhs_nulls,
286 )));
287
288 let result = nullif_func(&[lhs, rhs])?;
289 let result = result.into_array(0).expect("Failed to convert to array");
290
291 let expected_arrays = vec![
292 Arc::new(Int64Array::from(vec![None, Some(2), None])) as ArrayRef,
293 Arc::new(StringArray::from(vec![None, Some("2"), None])) as ArrayRef,
294 ];
295 let expected_nulls = NullBuffer::from(vec![false, true, false]);
296
297 let expected = Arc::new(StructArray::try_new(
298 fields,
299 expected_arrays,
300 Some(expected_nulls),
301 )?) as ArrayRef;
302
303 assert_eq!(expected.as_ref(), result.as_ref());
304
305 Ok(())
306 }
307
308 #[test]
309 fn nullif_list() -> Result<()> {

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
nullif_funcFunction · 0.85
cloneMethod · 0.45
into_arrayMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…