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

Method invoke_with_args

datafusion/functions/src/regex/regexpcount.rs:107–132  ·  view source on GitHub ↗
(&self, args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

105 }
106
107 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
108 let args = &args.args;
109
110 let len = args
111 .iter()
112 .fold(Option::<usize>::None, |acc, arg| match arg {
113 ColumnarValue::Scalar(_) => acc,
114 ColumnarValue::Array(a) => Some(a.len()),
115 });
116
117 let is_scalar = len.is_none();
118 let inferred_length = len.unwrap_or(1);
119 let args = args
120 .iter()
121 .map(|arg| arg.to_array(inferred_length))
122 .collect::<Result<Vec<_>>>()?;
123
124 let result = regexp_count_func(&args);
125 if is_scalar {
126 // If all inputs are scalar, keeps output as scalar
127 let result = result.and_then(|arr| ScalarValue::try_from_array(&arr, 0));
128 result.map(ColumnarValue::Scalar)
129 } else {
130 result.map(ColumnarValue::Array)
131 }
132 }
133
134 fn documentation(&self) -> Option<&Documentation> {
135 self.doc()

Callers 1

Calls 6

regexp_count_funcFunction · 0.85
is_noneMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45
mapMethod · 0.45
to_arrayMethod · 0.45

Tested by

no test coverage detected