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

Function simplify_concat_ws

datafusion/functions/src/string/concat_ws.rs:401–521  ·  view source on GitHub ↗
(delimiter: &Expr, args: &[Expr])

Source from the content-addressed store, hash-verified

399}
400
401fn simplify_concat_ws(delimiter: &Expr, args: &[Expr]) -> Result<ExprSimplifyResult> {
402 // Preserve the delimiter's string type for any new literals produced
403 // during simplification.
404 let delimiter_type = match delimiter {
405 Expr::Literal(v, _) => v.data_type(),
406 _ => DataType::Utf8,
407 };
408
409 let typed_lit = |s: String| -> Expr {
410 match delimiter_type {
411 DataType::LargeUtf8 => lit(ScalarValue::LargeUtf8(Some(s))),
412 DataType::Utf8View => lit(ScalarValue::Utf8View(Some(s))),
413 _ => lit(s),
414 }
415 };
416
417 match delimiter {
418 Expr::Literal(
419 ScalarValue::Utf8(delimiter)
420 | ScalarValue::LargeUtf8(delimiter)
421 | ScalarValue::Utf8View(delimiter),
422 _,
423 ) => {
424 match delimiter {
425 // When the delimiter is the empty string, replace `concat_ws`
426 // with `concat`
427 Some(delimiter) if delimiter.is_empty() => {
428 match simplify_concat(args.to_vec())? {
429 ExprSimplifyResult::Original(_) => {
430 Ok(ExprSimplifyResult::Simplified(Expr::ScalarFunction(
431 ScalarFunction {
432 func: concat(),
433 args: args.to_vec(),
434 },
435 )))
436 }
437 expr => Ok(expr),
438 }
439 }
440 Some(delimiter) => {
441 let mut new_args = Vec::with_capacity(args.len());
442 new_args.push(typed_lit(delimiter.to_string()));
443 let mut contiguous_scalar = None;
444 for arg in args {
445 match arg {
446 // filter out null args
447 Expr::Literal(
448 ScalarValue::Utf8(None)
449 | ScalarValue::LargeUtf8(None)
450 | ScalarValue::Utf8View(None),
451 _,
452 ) => {}
453 Expr::Literal(
454 ScalarValue::Utf8(Some(v))
455 | ScalarValue::LargeUtf8(Some(v))
456 | ScalarValue::Utf8View(Some(v)),
457 _,
458 ) => match contiguous_scalar {

Callers 1

simplifyMethod · 0.85

Calls 15

simplify_concatFunction · 0.85
ScalarFunctionClass · 0.85
to_vecMethod · 0.80
concatFunction · 0.70
concat_wsFunction · 0.70
is_nullFunction · 0.70
litFunction · 0.50
LiteralInterface · 0.50
data_typeMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…