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

Method invoke_with_args

datafusion/functions/src/regex/regexpinstr.rs:124–149  ·  view source on GitHub ↗
(&self, args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

122 }
123
124 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
125 let args = &args.args;
126
127 let len = args
128 .iter()
129 .fold(Option::<usize>::None, |acc, arg| match arg {
130 ColumnarValue::Scalar(_) => acc,
131 ColumnarValue::Array(a) => Some(a.len()),
132 });
133
134 let is_scalar = len.is_none();
135 let inferred_length = len.unwrap_or(1);
136 let args = args
137 .iter()
138 .map(|arg| arg.to_array(inferred_length))
139 .collect::<Result<Vec<_>>>()?;
140
141 let result = regexp_instr_func(&args);
142 if is_scalar {
143 // If all inputs are scalar, keeps output as scalar
144 let result = result.and_then(|arr| ScalarValue::try_from_array(&arr, 0));
145 result.map(ColumnarValue::Scalar)
146 } else {
147 result.map(ColumnarValue::Array)
148 }
149 }
150
151 fn documentation(&self) -> Option<&Documentation> {
152 self.doc()

Callers 1

Calls 6

regexp_instr_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