MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / string_to_array_impl

Function string_to_array_impl

src/expr/src/scalar/func/variadic.rs:1348–1383  ·  view source on GitHub ↗
(
    string: &str,
    delimiter: &str,
    null_string: Option<&'a str>,
    temp_storage: &'a RowArena,
)

Source from the content-addressed store, hash-verified

1346}
1347
1348fn string_to_array_impl<'a>(
1349 string: &str,
1350 delimiter: &str,
1351 null_string: Option<&'a str>,
1352 temp_storage: &'a RowArena,
1353) -> Result<Datum<'a>, EvalError> {
1354 let mut row = Row::default();
1355 let mut packer = row.packer();
1356
1357 let result = string.split(delimiter);
1358 let found: Vec<&str> = if delimiter.is_empty() {
1359 result.filter(|s| !s.is_empty()).collect()
1360 } else {
1361 result.collect()
1362 };
1363 let array_dimensions = [ArrayDimension {
1364 lower_bound: 1,
1365 length: found.len(),
1366 }];
1367
1368 if let Some(null_string) = null_string {
1369 let found_datums = found.into_iter().map(|chunk| {
1370 if chunk.eq(null_string) {
1371 Datum::Null
1372 } else {
1373 Datum::String(chunk)
1374 }
1375 });
1376
1377 packer.try_push_array(&array_dimensions, found_datums)?;
1378 } else {
1379 packer.try_push_array(&array_dimensions, found.into_iter().map(Datum::String))?;
1380 }
1381
1382 Ok(temp_storage.push_unary_row(row))
1383}
1384
1385#[sqlfunc]
1386fn substr<'a>(s: &'a str, start: i32, length: OptionalArg<i32>) -> Result<&'a str, EvalError> {

Callers 1

string_to_arrayFunction · 0.85

Calls 12

StringClass · 0.85
packerMethod · 0.80
try_push_arrayMethod · 0.80
push_unary_rowMethod · 0.80
splitMethod · 0.45
is_emptyMethod · 0.45
collectMethod · 0.45
filterMethod · 0.45
lenMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
eqMethod · 0.45

Tested by

no test coverage detected