@@ -31,8 +31,8 @@ use crate::logical_plan::Expr::Alias;
3131use crate :: logical_plan:: {
3232 and, builder:: expand_qualified_wildcard, builder:: expand_wildcard, col, lit,
3333 normalize_col, rewrite_udtfs_to_columns, Column , CreateMemoryTable , DFSchema ,
34- DFSchemaRef , DropTable , Expr , LogicalPlan , LogicalPlanBuilder , Operator , PlanType ,
35- ToDFSchema , ToStringifiedPlan ,
34+ DFSchemaRef , DropTable , Expr , ExprSchemable , LogicalPlan , LogicalPlanBuilder ,
35+ Operator , PlanType , ToDFSchema , ToStringifiedPlan ,
3636} ;
3737use crate :: optimizer:: utils:: exprlist_to_columns;
3838use crate :: prelude:: JoinType ;
@@ -2002,42 +2002,52 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
20022002 }
20032003
20042004 SQLExpr :: Like { negated, expr, pattern, escape_char } => {
2005- match escape_char {
2006- Some ( _) => {
2007- // to support this we will need to introduce `Expr::Like` instead
2008- // of treating it like a binary expression
2009- Err ( DataFusionError :: NotImplemented ( "LIKE with ESCAPE is not yet supported" . to_string ( ) ) )
2010- } ,
2011- _ => {
2012- Ok ( Expr :: BinaryExpr {
2013- left : Box :: new ( self . sql_expr_to_logical_expr ( * expr, schema, ) ?) ,
2014- op : if negated { Operator :: NotLike } else { Operator :: Like } ,
2015- right : Box :: new ( self . sql_expr_to_logical_expr ( * pattern, schema) ?) ,
2016- } )
2017- }
2005+ let pattern = self . sql_expr_to_logical_expr ( * pattern, schema) ?;
2006+ let pattern_type = pattern. get_type ( schema) ?;
2007+ if pattern_type != DataType :: Utf8 && pattern_type != DataType :: Null {
2008+ return Err ( DataFusionError :: Plan (
2009+ "Invalid pattern in LIKE expression" . to_string ( ) ,
2010+ ) ) ;
20182011 }
2012+ Ok ( Expr :: Like {
2013+ negated,
2014+ expr : Box :: new ( self . sql_expr_to_logical_expr ( * expr, schema) ?) ,
2015+ pattern : Box :: new ( pattern) ,
2016+ escape_char
2017+
2018+ } )
20192019 }
20202020
20212021 SQLExpr :: ILike { negated, expr, pattern, escape_char } => {
2022- match escape_char {
2023- Some ( _) => {
2024- // to support this we will need to introduce `Expr::ILike` instead
2025- // of treating it like a binary expression
2026- Err ( DataFusionError :: NotImplemented ( "ILIKE with ESCAPE is not yet supported" . to_string ( ) ) )
2027- } ,
2028- _ => {
2029- Ok ( Expr :: BinaryExpr {
2030- left : Box :: new ( self . sql_expr_to_logical_expr ( * expr, schema, ) ?) ,
2031- op : if negated { Operator :: NotILike } else { Operator :: ILike } ,
2032- right : Box :: new ( self . sql_expr_to_logical_expr ( * pattern, schema) ?) ,
2033- } )
2034- }
2022+ let pattern = self . sql_expr_to_logical_expr ( * pattern, schema) ?;
2023+ let pattern_type = pattern. get_type ( schema) ?;
2024+ if pattern_type != DataType :: Utf8 && pattern_type != DataType :: Null {
2025+ return Err ( DataFusionError :: Plan (
2026+ "Invalid pattern in ILIKE expression" . to_string ( ) ,
2027+ ) ) ;
20352028 }
2029+ Ok ( Expr :: ILike {
2030+ negated,
2031+ expr : Box :: new ( self . sql_expr_to_logical_expr ( * expr, schema) ?) ,
2032+ pattern : Box :: new ( pattern) ,
2033+ escape_char
2034+ } )
20362035 }
20372036
2038- SQLExpr :: SimilarTo { .. } => {
2039- // https://github.com/apache/arrow-datafusion/issues/3099
2040- Err ( DataFusionError :: NotImplemented ( "SIMILAR TO is not yet supported" . to_string ( ) ) )
2037+ SQLExpr :: SimilarTo { negated, expr, pattern, escape_char } => {
2038+ let pattern = self . sql_expr_to_logical_expr ( * pattern, schema) ?;
2039+ let pattern_type = pattern. get_type ( schema) ?;
2040+ if pattern_type != DataType :: Utf8 && pattern_type != DataType :: Null {
2041+ return Err ( DataFusionError :: Plan (
2042+ "Invalid pattern in SIMILAR TO expression" . to_string ( ) ,
2043+ ) ) ;
2044+ }
2045+ Ok ( Expr :: SimilarTo {
2046+ negated,
2047+ expr : Box :: new ( self . sql_expr_to_logical_expr ( * expr, schema) ?) ,
2048+ pattern : Box :: new ( pattern) ,
2049+ escape_char
2050+ } )
20412051 }
20422052
20432053 SQLExpr :: BinaryOp {
0 commit comments