(args: Vec<Expr>)
| 308 | } |
| 309 | |
| 310 | pub(crate) fn simplify_concat(args: Vec<Expr>) -> Result<ExprSimplifyResult> { |
| 311 | let mut new_args = Vec::with_capacity(args.len()); |
| 312 | let mut contiguous_scalar = "".to_string(); |
| 313 | |
| 314 | let return_type = { |
| 315 | let data_types: Vec<_> = args |
| 316 | .iter() |
| 317 | .filter_map(|expr| match expr { |
| 318 | Expr::Literal(l, _) => Some(l.data_type()), |
| 319 | _ => None, |
| 320 | }) |
| 321 | .collect(); |
| 322 | ConcatFunc::new().return_type(&data_types) |
| 323 | }?; |
| 324 | |
| 325 | for arg in args.clone() { |
| 326 | match arg { |
| 327 | Expr::Literal(ScalarValue::Utf8(None), _) => {} |
| 328 | Expr::Literal(ScalarValue::LargeUtf8(None), _) => {} |
| 329 | Expr::Literal(ScalarValue::Utf8View(None), _) => {} |
| 330 | |
| 331 | // filter out `null` args |
| 332 | // All literals have been converted to Utf8 or LargeUtf8 in type_coercion. |
| 333 | // Concatenate it with the `contiguous_scalar`. |
| 334 | Expr::Literal(ScalarValue::Utf8(Some(v)), _) => { |
| 335 | contiguous_scalar += &v; |
| 336 | } |
| 337 | Expr::Literal(ScalarValue::LargeUtf8(Some(v)), _) => { |
| 338 | contiguous_scalar += &v; |
| 339 | } |
| 340 | Expr::Literal(ScalarValue::Utf8View(Some(v)), _) => { |
| 341 | contiguous_scalar += &v; |
| 342 | } |
| 343 | |
| 344 | Expr::Literal(x, _) => { |
| 345 | return internal_err!( |
| 346 | "The scalar {x} should be casted to string type during the type coercion." |
| 347 | ); |
| 348 | } |
| 349 | // If the arg is not a literal, we should first push the current `contiguous_scalar` |
| 350 | // to the `new_args` (if it is not empty) and reset it to empty string. |
| 351 | // Then pushing this arg to the `new_args`. |
| 352 | arg => { |
| 353 | if !contiguous_scalar.is_empty() { |
| 354 | match return_type { |
| 355 | DataType::Utf8 => new_args.push(lit(contiguous_scalar)), |
| 356 | DataType::LargeUtf8 => new_args |
| 357 | .push(lit(ScalarValue::LargeUtf8(Some(contiguous_scalar)))), |
| 358 | DataType::Utf8View => new_args |
| 359 | .push(lit(ScalarValue::Utf8View(Some(contiguous_scalar)))), |
| 360 | _ => unreachable!(), |
| 361 | } |
| 362 | contiguous_scalar = "".to_string(); |
| 363 | } |
| 364 | new_args.push(arg); |
| 365 | } |
| 366 | } |
| 367 | } |
no test coverage detected
searching dependent graphs…