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

Function regexp_instr

datafusion/functions/src/regex/regexpinstr.rs:203–282  ·  view source on GitHub ↗

`arrow-rs` style implementation of `regexp_instr` function. This function `regexp_instr` is responsible for returning the index of a regular expression pattern within a string array. It supports optional start positions and flags for case insensitivity. The function accepts a variable number of arguments: - `values`: The array of strings to search within. - `regex_array`: The array of regular exp

(
    values: &dyn Array,
    regex_array: &dyn Datum,
    start_array: Option<&dyn Datum>,
    nth_array: Option<&dyn Datum>,
    flags_array: Option<&dyn Datum>,
    subexpr_array: Option<&dyn Datum

Source from the content-addressed store, hash-verified

201/// # Errors
202/// Returns an error if the input arrays have mismatched lengths or if the regular expression fails to compile.
203fn regexp_instr(
204 values: &dyn Array,
205 regex_array: &dyn Datum,
206 start_array: Option<&dyn Datum>,
207 nth_array: Option<&dyn Datum>,
208 flags_array: Option<&dyn Datum>,
209 subexpr_array: Option<&dyn Datum>,
210) -> Result<ArrayRef, ArrowError> {
211 let (regex_array, _) = regex_array.get();
212 let start_array = start_array.map(|start| {
213 let (start, _) = start.get();
214 start
215 });
216 let nth_array = nth_array.map(|nth| {
217 let (nth, _) = nth.get();
218 nth
219 });
220 let flags_array = flags_array.map(|flags| {
221 let (flags, _) = flags.get();
222 flags
223 });
224 let subexpr_array = subexpr_array.map(|subexpr| {
225 let (subexpr, _) = subexpr.get();
226 subexpr
227 });
228
229 match (values.data_type(), regex_array.data_type(), flags_array) {
230 (Utf8, Utf8, None) => regexp_instr_inner(
231 &values.as_string::<i32>(),
232 &regex_array.as_string::<i32>(),
233 start_array.map(|start| start.as_primitive::<Int64Type>()),
234 nth_array.map(|nth| nth.as_primitive::<Int64Type>()),
235 None,
236 subexpr_array.map(|subexpr| subexpr.as_primitive::<Int64Type>()),
237 ),
238 (Utf8, Utf8, Some(flags_array)) if *flags_array.data_type() == Utf8 => regexp_instr_inner(
239 &values.as_string::<i32>(),
240 &regex_array.as_string::<i32>(),
241 start_array.map(|start| start.as_primitive::<Int64Type>()),
242 nth_array.map(|nth| nth.as_primitive::<Int64Type>()),
243 Some(flags_array.as_string::<i32>()),
244 subexpr_array.map(|subexpr| subexpr.as_primitive::<Int64Type>()),
245 ),
246 (LargeUtf8, LargeUtf8, None) => regexp_instr_inner(
247 &values.as_string::<i64>(),
248 &regex_array.as_string::<i64>(),
249 start_array.map(|start| start.as_primitive::<Int64Type>()),
250 nth_array.map(|nth| nth.as_primitive::<Int64Type>()),
251 None,
252 subexpr_array.map(|subexpr| subexpr.as_primitive::<Int64Type>()),
253 ),
254 (LargeUtf8, LargeUtf8, Some(flags_array)) if *flags_array.data_type() == LargeUtf8 => regexp_instr_inner(
255 &values.as_string::<i64>(),
256 &regex_array.as_string::<i64>(),
257 start_array.map(|start| start.as_primitive::<Int64Type>()),
258 nth_array.map(|nth| nth.as_primitive::<Int64Type>()),
259 Some(flags_array.as_string::<i64>()),
260 subexpr_array.map(|subexpr| subexpr.as_primitive::<Int64Type>()),

Callers 1

regexp_instr_funcFunction · 0.70

Calls 5

regexp_instr_innerFunction · 0.85
getMethod · 0.45
mapMethod · 0.45
data_typeMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…