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

Function string_to_array

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

Source from the content-addressed store, hash-verified

1301 propagates_nulls = false
1302)]
1303fn string_to_array<'a>(
1304 string: &'a str,
1305 delimiter: Option<&'a str>,
1306 null_string: OptionalArg<Option<&'a str>>,
1307 temp_storage: &'a RowArena,
1308) -> Result<Datum<'a>, EvalError> {
1309 if string.is_empty() {
1310 let mut row = Row::default();
1311 let mut packer = row.packer();
1312 packer.try_push_array(&[], std::iter::empty::<Datum>())?;
1313
1314 return Ok(temp_storage.push_unary_row(row));
1315 }
1316
1317 let Some(delimiter) = delimiter else {
1318 let split_all_chars_delimiter = "";
1319 return string_to_array_impl(
1320 string,
1321 split_all_chars_delimiter,
1322 null_string.flatten(),
1323 temp_storage,
1324 );
1325 };
1326
1327 if delimiter.is_empty() {
1328 let mut row = Row::default();
1329 let mut packer = row.packer();
1330 let dims = &[ArrayDimension {
1331 lower_bound: 1,
1332 length: 1,
1333 }];
1334 match null_string.flatten() {
1335 Some(null_string) if null_string == string => {
1336 packer.try_push_array(dims, std::iter::once(Datum::Null))?;
1337 }
1338 _ => {
1339 packer.try_push_array(dims, vec![string].into_iter().map(Datum::String))?;
1340 }
1341 }
1342 Ok(temp_storage.push_unary_row(row))
1343 } else {
1344 string_to_array_impl(string, delimiter, null_string.flatten(), temp_storage)
1345 }
1346}
1347
1348fn string_to_array_impl<'a>(
1349 string: &str,

Callers

nothing calls this directly

Calls 8

string_to_array_implFunction · 0.85
packerMethod · 0.80
try_push_arrayMethod · 0.80
push_unary_rowMethod · 0.80
is_emptyMethod · 0.45
flattenMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected