(
&self,
expr: SQLExpr,
trim_where: Option<TrimWhereField>,
trim_what: Option<Box<SQLExpr>>,
trim_characters: Option<Vec<SQLExpr>>,
schema: &DFSchema,
| 955 | } |
| 956 | |
| 957 | fn sql_trim_to_expr( |
| 958 | &self, |
| 959 | expr: SQLExpr, |
| 960 | trim_where: Option<TrimWhereField>, |
| 961 | trim_what: Option<Box<SQLExpr>>, |
| 962 | trim_characters: Option<Vec<SQLExpr>>, |
| 963 | schema: &DFSchema, |
| 964 | planner_context: &mut PlannerContext, |
| 965 | ) -> Result<Expr> { |
| 966 | let arg = self.sql_expr_to_logical_expr(expr, schema, planner_context)?; |
| 967 | let args = match (trim_what, trim_characters) { |
| 968 | (Some(to_trim), None) => { |
| 969 | let to_trim = |
| 970 | self.sql_expr_to_logical_expr(*to_trim, schema, planner_context)?; |
| 971 | Ok(vec![arg, to_trim]) |
| 972 | } |
| 973 | (None, Some(trim_characters)) => { |
| 974 | if let Some(first) = trim_characters.first() { |
| 975 | let to_trim = self.sql_expr_to_logical_expr( |
| 976 | first.clone(), |
| 977 | schema, |
| 978 | planner_context, |
| 979 | )?; |
| 980 | Ok(vec![arg, to_trim]) |
| 981 | } else { |
| 982 | plan_err!("TRIM CHARACTERS cannot be empty") |
| 983 | } |
| 984 | } |
| 985 | (Some(_), Some(_)) => { |
| 986 | plan_err!("Both TRIM and TRIM CHARACTERS cannot be specified") |
| 987 | } |
| 988 | (None, None) => Ok(vec![arg]), |
| 989 | }?; |
| 990 | |
| 991 | let fun_name = match trim_where { |
| 992 | Some(TrimWhereField::Leading) => "ltrim", |
| 993 | Some(TrimWhereField::Trailing) => "rtrim", |
| 994 | Some(TrimWhereField::Both) => "btrim", |
| 995 | None => "trim", |
| 996 | }; |
| 997 | let fun = self |
| 998 | .context_provider |
| 999 | .get_function_meta(fun_name) |
| 1000 | .ok_or_else(|| { |
| 1001 | internal_datafusion_err!("Unable to find expected '{fun_name}' function") |
| 1002 | })?; |
| 1003 | |
| 1004 | Ok(Expr::ScalarFunction(ScalarFunction::new_udf(fun, args))) |
| 1005 | } |
| 1006 | |
| 1007 | fn sql_overlay_to_expr( |
| 1008 | &self, |
no test coverage detected