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

Function array_has_any_with_scalar

datafusion/functions-nested/src/array_has.rs:567–594  ·  view source on GitHub ↗

Fast path for `array_has_any` when exactly one argument is a scalar.

(
    columnar_arg: &ColumnarValue,
    scalar_arg: &ScalarValue,
)

Source from the content-addressed store, hash-verified

565
566/// Fast path for `array_has_any` when exactly one argument is a scalar.
567fn array_has_any_with_scalar(
568 columnar_arg: &ColumnarValue,
569 scalar_arg: &ScalarValue,
570) -> Result<ColumnarValue> {
571 if scalar_arg.is_null() {
572 return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(None)));
573 }
574
575 // Convert the scalar to a 1-element ListArray, then extract the inner values
576 let scalar_array = scalar_arg.to_array_of_size(1)?;
577 let scalar_list: ArrayWrapper = scalar_array.as_ref().try_into()?;
578 let offsets: Vec<usize> = scalar_list.offsets().collect();
579 let scalar_values = scalar_list
580 .values()
581 .slice(offsets[0], offsets[1] - offsets[0]);
582
583 // If scalar list is empty, result is always false
584 if scalar_values.is_empty() {
585 return Ok(ColumnarValue::Scalar(ScalarValue::Boolean(Some(false))));
586 }
587
588 match scalar_values.data_type() {
589 DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View => {
590 array_has_any_with_scalar_string(columnar_arg, &scalar_values)
591 }
592 _ => array_has_any_with_scalar_general(columnar_arg, &scalar_values),
593 }
594}
595
596/// When the scalar argument has more elements than this, the scalar fast path
597/// builds a HashSet for O(1) lookups. At or below this threshold, it falls

Callers 1

invoke_with_argsMethod · 0.85

Calls 11

collectMethod · 0.80
offsetsMethod · 0.80
sliceMethod · 0.80
is_nullMethod · 0.45
to_array_of_sizeMethod · 0.45
as_refMethod · 0.45
valuesMethod · 0.45
is_emptyMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…