Skip to content

Commit c51bba2

Browse files
committed
Support ILIKE operators
1 parent 9a61c00 commit c51bba2

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

datafusion/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ahash = "0.7"
4848
hashbrown = "0.11"
4949
arrow = { git = "https://github.com/cube-js/arrow-rs.git", branch = "cube", features = ["prettyprint"] }
5050
parquet = { git = "https://github.com/cube-js/arrow-rs.git", branch = "cube", features = ["arrow"] }
51-
sqlparser = { git = "https://github.com/cube-js/sqlparser-rs.git", rev = "b1d144a2cb5cc47ac950fd1d518bc28b4dc33ab9" }
51+
sqlparser = { git = "https://github.com/cube-js/sqlparser-rs.git", rev = "c3c77dd2aa408a7cb0c9f27e5e9fc1b101351dcd" }
5252
paste = "^1.0"
5353
num_cpus = "1.13.0"
5454
chrono = "0.4"

datafusion/src/logical_plan/expr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ impl Expr {
615615
binary_expr(self, Operator::NotLike, other)
616616
}
617617

618+
/// Return `self LIKE other`
619+
pub fn ilike(self, other: Expr) -> Expr {
620+
binary_expr(self, Operator::ILike, other)
621+
}
622+
623+
/// Return `self NOT LIKE other`
624+
pub fn not_ilike(self, other: Expr) -> Expr {
625+
binary_expr(self, Operator::NotILike, other)
626+
}
627+
618628
/// Return `self AS name` alias expression
619629
pub fn alias(self, name: &str) -> Expr {
620630
Expr::Alias(Box::new(self), name.to_owned())

datafusion/src/logical_plan/operators.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ pub enum Operator {
5353
Like,
5454
/// Does not match a wildcard pattern
5555
NotLike,
56+
/// Matches a wildcard pattern (case-insensitive)
57+
ILike,
58+
/// Does not match a wildcard pattern (case-insensitive)
59+
NotILike,
5660
}
5761

5862
impl fmt::Display for Operator {
@@ -73,6 +77,8 @@ impl fmt::Display for Operator {
7377
Operator::Or => "OR",
7478
Operator::Like => "LIKE",
7579
Operator::NotLike => "NOT LIKE",
80+
Operator::ILike => "ILIKE",
81+
Operator::NotILike => "NOT ILIKE",
7682
};
7783
write!(f, "{}", display)
7884
}

datafusion/src/physical_plan/expressions/binary.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ use arrow::compute::kernels::comparison::{
3232
eq_scalar, gt_eq_scalar, gt_scalar, lt_eq_scalar, lt_scalar, neq_scalar,
3333
};
3434
use arrow::compute::kernels::comparison::{
35-
eq_utf8, gt_eq_utf8, gt_utf8, like_utf8, like_utf8_scalar, lt_eq_utf8, lt_utf8,
36-
neq_utf8, nlike_utf8, nlike_utf8_scalar,
35+
eq_utf8, gt_eq_utf8, gt_utf8, ilike_utf8, ilike_utf8_scalar, like_utf8,
36+
like_utf8_scalar, lt_eq_utf8, lt_utf8, neq_utf8, nilike_utf8, nilike_utf8_scalar,
37+
nlike_utf8, nlike_utf8_scalar,
3738
};
3839
use arrow::compute::kernels::comparison::{
3940
eq_utf8_scalar, gt_eq_utf8_scalar, gt_utf8_scalar, lt_eq_utf8_scalar, lt_utf8_scalar,
@@ -503,7 +504,9 @@ fn common_binary_type(
503504
// logical equality operators have their own rules, and always return a boolean
504505
Operator::Eq | Operator::NotEq => eq_coercion(lhs_type, rhs_type),
505506
// "like" operators operate on strings and always return a boolean
506-
Operator::Like | Operator::NotLike => string_coercion(lhs_type, rhs_type),
507+
Operator::Like | Operator::NotLike | Operator::ILike | Operator::NotILike => {
508+
string_coercion(lhs_type, rhs_type)
509+
}
507510
// order-comparison operators have their own rules
508511
Operator::Lt | Operator::Gt | Operator::GtEq | Operator::LtEq => {
509512
order_coercion(lhs_type, rhs_type)
@@ -552,6 +555,8 @@ pub fn binary_operator_data_type(
552555
| Operator::Or
553556
| Operator::Like
554557
| Operator::NotLike
558+
| Operator::ILike
559+
| Operator::NotILike
555560
| Operator::Lt
556561
| Operator::Gt
557562
| Operator::GtEq
@@ -618,6 +623,12 @@ impl PhysicalExpr for BinaryExpr {
618623
Operator::NotLike => {
619624
binary_string_array_op_scalar!(array, scalar.clone(), nlike)
620625
}
626+
Operator::ILike => {
627+
binary_string_array_op_scalar!(array, scalar.clone(), ilike)
628+
}
629+
Operator::NotILike => {
630+
binary_string_array_op_scalar!(array, scalar.clone(), nilike)
631+
}
621632
Operator::Divide => {
622633
binary_primitive_array_op_scalar!(array, scalar.clone(), divide)
623634
}
@@ -685,6 +696,8 @@ impl PhysicalExpr for BinaryExpr {
685696
let result: Result<ArrayRef> = match &self.op {
686697
Operator::Like => binary_string_array_op!(left, right, like),
687698
Operator::NotLike => binary_string_array_op!(left, right, nlike),
699+
Operator::ILike => binary_string_array_op!(left, right, ilike),
700+
Operator::NotILike => binary_string_array_op!(left, right, nilike),
688701
Operator::Lt => binary_array_op!(left, right, lt),
689702
Operator::LtEq => binary_array_op!(left, right, lt_eq),
690703
Operator::Gt => binary_array_op!(left, right, gt),

datafusion/src/sql/planner.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
13481348
BinaryOperator::Or => Ok(Operator::Or),
13491349
BinaryOperator::Like => Ok(Operator::Like),
13501350
BinaryOperator::NotLike => Ok(Operator::NotLike),
1351+
BinaryOperator::ILike => Ok(Operator::ILike),
1352+
BinaryOperator::NotILike => Ok(Operator::NotILike),
13511353
_ => Err(DataFusionError::NotImplemented(format!(
13521354
"Unsupported SQL binary operator {:?}",
13531355
op

0 commit comments

Comments
 (0)