@@ -477,11 +477,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
477
477
expr,
478
478
trim_where,
479
479
trim_what,
480
+ trim_characters,
480
481
..
481
482
} => self . sql_trim_to_expr (
482
483
* expr,
483
484
trim_where,
484
485
trim_what,
486
+ trim_characters,
485
487
schema,
486
488
planner_context,
487
489
) ,
@@ -708,6 +710,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
708
710
expr : SQLExpr ,
709
711
trim_where : Option < TrimWhereField > ,
710
712
trim_what : Option < Box < SQLExpr > > ,
713
+ trim_characters : Option < Vec < SQLExpr > > ,
711
714
schema : & DFSchema ,
712
715
planner_context : & mut PlannerContext ,
713
716
) -> Result < Expr > {
@@ -717,15 +720,31 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
717
720
Some ( TrimWhereField :: Both ) => BuiltinScalarFunction :: Btrim ,
718
721
None => BuiltinScalarFunction :: Trim ,
719
722
} ;
723
+
720
724
let arg = self . sql_expr_to_logical_expr ( expr, schema, planner_context) ?;
721
- let args = match trim_what {
722
- Some ( to_trim) => {
725
+ let args = match ( trim_what, trim_characters ) {
726
+ ( Some ( to_trim) , None ) => {
723
727
let to_trim =
724
728
self . sql_expr_to_logical_expr ( * to_trim, schema, planner_context) ?;
725
- vec ! [ arg, to_trim]
729
+ Ok ( vec ! [ arg, to_trim] )
726
730
}
727
- None => vec ! [ arg] ,
728
- } ;
731
+ ( None , Some ( trim_characters) ) => {
732
+ if let Some ( first) = trim_characters. first ( ) {
733
+ let to_trim = self . sql_expr_to_logical_expr (
734
+ first. clone ( ) ,
735
+ schema,
736
+ planner_context,
737
+ ) ?;
738
+ Ok ( vec ! [ arg, to_trim] )
739
+ } else {
740
+ plan_err ! ( "TRIM CHARACTERS cannot be empty" )
741
+ }
742
+ }
743
+ ( Some ( _) , Some ( _) ) => {
744
+ plan_err ! ( "Both TRIM and TRIM CHARACTERS cannot be specified" )
745
+ }
746
+ ( None , None ) => Ok ( vec ! [ arg] ) ,
747
+ } ?;
729
748
Ok ( Expr :: ScalarFunction ( ScalarFunction :: new ( fun, args) ) )
730
749
}
731
750
0 commit comments