-
Notifications
You must be signed in to change notification settings - Fork 972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SQL planner support for Like
, ILike
and SimilarTo
, with optional escape character
#3101
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
64e8559
Make Like a top-level Expr
andygrove d1d6655
revert some changes
andygrove bd14a93
add type validation
andygrove 41f7db1
Revert physical plan changes and reduce scope of the PR
andygrove 718c304
Revert more changes
andygrove 64dbd31
Revert more changes
andygrove 4882a98
upmerge
andygrove df73d16
clippy
andygrove 63bf702
upmerge
andygrove 3a86db8
address feedback
andygrove 8ea73b1
revert change to test
andygrove a18dec8
revert more changes
andygrove File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,8 @@ use datafusion_expr::utils::{ | |
COUNT_STAR_EXPANSION, | ||
}; | ||
use datafusion_expr::{ | ||
and, col, lit, AggregateFunction, AggregateUDF, Expr, Operator, ScalarUDF, | ||
WindowFrame, WindowFrameUnits, | ||
and, col, lit, AggregateFunction, AggregateUDF, Expr, ExprSchemable, Operator, | ||
ScalarUDF, WindowFrame, WindowFrameUnits, | ||
}; | ||
use datafusion_expr::{ | ||
window_function::WindowFunction, BuiltinScalarFunction, TableSource, | ||
|
@@ -1939,30 +1939,52 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | |
} | ||
|
||
SQLExpr::Like { negated, expr, pattern, escape_char } => { | ||
match escape_char { | ||
Some(_) => { | ||
// to support this we will need to introduce `Expr::Like` instead | ||
// of treating it like a binary expression | ||
Err(DataFusionError::NotImplemented("LIKE with ESCAPE is not yet supported".to_string())) | ||
}, | ||
_ => { | ||
Ok(Expr::BinaryExpr { | ||
left: Box::new(self.sql_expr_to_logical_expr(*expr, schema, ctes)?), | ||
op: if negated { Operator::NotLike } else { Operator::Like }, | ||
right: Box::new(self.sql_expr_to_logical_expr(*pattern, schema, ctes)?), | ||
}) | ||
} | ||
let pattern = self.sql_expr_to_logical_expr(*pattern, schema, ctes)?; | ||
let pattern_type = pattern.get_type(schema)?; | ||
if pattern_type != DataType::Utf8 && pattern_type != DataType::Null { | ||
return Err(DataFusionError::Plan( | ||
"Invalid pattern in LIKE expression".to_string(), | ||
)); | ||
} | ||
Ok(Expr::Like { | ||
negated, | ||
expr: Box::new(self.sql_expr_to_logical_expr(*expr, schema, ctes)?), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
pattern: Box::new(pattern), | ||
escape_char | ||
|
||
}) | ||
} | ||
|
||
SQLExpr::ILike { .. } => { | ||
// https://github.com/apache/arrow-datafusion/issues/3099 | ||
Err(DataFusionError::NotImplemented("ILIKE is not yet supported".to_string())) | ||
SQLExpr::ILike { negated, expr, pattern, escape_char } => { | ||
let pattern = self.sql_expr_to_logical_expr(*pattern, schema, ctes)?; | ||
let pattern_type = pattern.get_type(schema)?; | ||
if pattern_type != DataType::Utf8 && pattern_type != DataType::Null { | ||
return Err(DataFusionError::Plan( | ||
"Invalid pattern in ILIKE expression".to_string(), | ||
)); | ||
} | ||
Ok(Expr::ILike { | ||
negated, | ||
expr: Box::new(self.sql_expr_to_logical_expr(*expr, schema, ctes)?), | ||
pattern: Box::new(pattern), | ||
escape_char | ||
}) | ||
} | ||
|
||
SQLExpr::SimilarTo { .. } => { | ||
// https://github.com/apache/arrow-datafusion/issues/3099 | ||
Err(DataFusionError::NotImplemented("SIMILAR TO is not yet supported".to_string())) | ||
SQLExpr::SimilarTo { negated, expr, pattern, escape_char } => { | ||
let pattern = self.sql_expr_to_logical_expr(*pattern, schema, ctes)?; | ||
let pattern_type = pattern.get_type(schema)?; | ||
if pattern_type != DataType::Utf8 && pattern_type != DataType::Null { | ||
return Err(DataFusionError::Plan( | ||
"Invalid pattern in SIMILAR TO expression".to_string(), | ||
)); | ||
} | ||
Ok(Expr::SimilarTo { | ||
negated, | ||
expr: Box::new(self.sql_expr_to_logical_expr(*expr, schema, ctes)?), | ||
pattern: Box::new(pattern), | ||
escape_char | ||
}) | ||
} | ||
|
||
SQLExpr::BinaryOp { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍