Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
[NSE-1079] Set the default escape char for like function (#1080)
Browse files Browse the repository at this point in the history
* Set the default escape char for like expression

* Add a test case
  • Loading branch information
PHILO-HE authored Aug 25, 2022
1 parent 604a3c2 commit 4ff7db5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,16 @@ class ColumnarLike(left: Expression, right: Expression, original: Expression)
}

override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = {
val (left_node, left_type): (TreeNode, ArrowType) =
val (left_node, _): (TreeNode, ArrowType) =
left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (right_node, right_type): (TreeNode, ArrowType) =
val (right_node, _): (TreeNode, ArrowType) =
right.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
// Currently, we only support "\" as the escape char, which is the default in spark.
val escapeNode = TreeBuilder.makeStringLiteral("\\")

val resultType = new ArrowType.Bool()
val funcNode =
TreeBuilder.makeFunction("like", Lists.newArrayList(left_node, right_node), resultType)
val funcNode = TreeBuilder.makeFunction("like",
Lists.newArrayList(left_node, right_node, escapeNode), resultType)
(funcNode, resultType)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ class NativeSQLConvertedSuite extends QueryTest
}

test("like") {
Seq(("google", "%oo%"),
("facebook", "%oo%"),
("linkedin", "%in"))
.toDF("company", "pat")
Seq(("google"),
("facebook"),
("linkedin"))
.toDF("company")
.createOrReplaceTempView("like_all_table")
val df = sql("SELECT company FROM like_all_table WHERE company LIKE ALL ('%oo%', pat)")
var df = sql("SELECT company FROM like_all_table WHERE company LIKE '%oo%'")
checkAnswer(df, Seq(Row("google"), Row("facebook")))

Seq(("http%3A%2F%2Fa%2Eb%2Ec%2Fd%2Fe"))
.toDF("url")
.createOrReplaceTempView("url_table")
df = sql("SELECT url LIKE '%a\\%2Eb\\%2Ec%' FROM url_table")
checkAnswer(df, Seq(Row(true)))
}

ignore("in-joins") {
Expand Down

0 comments on commit 4ff7db5

Please sign in to comment.