Skip to content

Commit 8b421c2

Browse files
committed
Handle the case where the final % is actually escaped.
1 parent d34d37e commit 8b421c2

File tree

1 file changed

+6
-3
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer

1 file changed

+6
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ object LikeSimplification extends Rule[LogicalPlan] {
123123
val contains = "%([^_%]+)%".r
124124

125125
def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
126-
case Like(l, Literal(startsWith(pattern), StringType)) => StartsWith(l, Literal(pattern))
127-
case Like(l, Literal(endsWith(pattern), StringType)) => EndsWith(l, Literal(pattern))
128-
case Like(l, Literal(contains(pattern), StringType)) => Contains(l, Literal(pattern))
126+
case Like(l, Literal(startsWith(pattern), StringType)) if !pattern.endsWith("\\") =>
127+
StartsWith(l, Literal(pattern))
128+
case Like(l, Literal(endsWith(pattern), StringType)) =>
129+
EndsWith(l, Literal(pattern))
130+
case Like(l, Literal(contains(pattern), StringType)) if !pattern.endsWith("\\") =>
131+
Contains(l, Literal(pattern))
129132
}
130133
}
131134

0 commit comments

Comments
 (0)