You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/11/14 07:48:20 UTC
[GitHub] [spark] wankunde opened a new pull request, #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
wankunde opened a new pull request, #38649:
URL: https://github.com/apache/spark/pull/38649
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
We can optimize query `SELECT * FROM tab WHERE trim(addr) LIKE ANY ('5000', '5001', '5002', '5003', '5004')` to `SELECT * FROM tab WHERE trim(addr) IN ('5000', '5001', '5002', '5003', '5004')`
### Why are the changes needed?
Match with set values will be faster than regex expressions.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Add UT
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on PR #38649:
URL: https://github.com/apache/spark/pull/38649#issuecomment-1313876520
Can one of the admins verify this patch?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] github-actions[bot] commented on pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #38649:
URL: https://github.com/apache/spark/pull/38649#issuecomment-1518903336
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] github-actions[bot] closed pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
URL: https://github.com/apache/spark/pull/38649
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wankunde commented on a diff in pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
Posted by GitBox <gi...@apache.org>.
wankunde commented on code in PR #38649:
URL: https://github.com/apache/spark/pull/38649#discussion_r1043018066
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -780,6 +780,13 @@ object LikeSimplification extends Rule[LogicalPlan] {
} else {
simplifyLike(input, pattern.toString, escapeChar).getOrElse(l)
}
+ case LikeAny(child, patterns)
+ if patterns.map(_.toString).forall { case equalTo(_) => true case _ => false } =>
+ InSet(child, patterns.toSet)
Review Comment:
Now support this pattern, and add UT
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a diff in pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
Posted by GitBox <gi...@apache.org>.
wangyum commented on code in PR #38649:
URL: https://github.com/apache/spark/pull/38649#discussion_r1043126971
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -762,10 +762,40 @@ object LikeSimplification extends Rule[LogicalPlan] with PredicateHelper {
val and = buildBalancedPredicate(replacements.map(Not(_)), And)
if (remainPatterns.nonEmpty) And(and, l.copy(patterns = remainPatterns)) else and
case l: LikeAny =>
- val or = buildBalancedPredicate(replacements, Or)
+ val equalPatterns = MutableHashset[Any]()
Review Comment:
Do you have some benchmark number?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wankunde commented on a diff in pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
Posted by GitBox <gi...@apache.org>.
wankunde commented on code in PR #38649:
URL: https://github.com/apache/spark/pull/38649#discussion_r1044038097
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -762,10 +762,40 @@ object LikeSimplification extends Rule[LogicalPlan] with PredicateHelper {
val and = buildBalancedPredicate(replacements.map(Not(_)), And)
if (remainPatterns.nonEmpty) And(and, l.copy(patterns = remainPatterns)) else and
case l: LikeAny =>
- val or = buildBalancedPredicate(replacements, Or)
+ val equalPatterns = MutableHashset[Any]()
Review Comment:
Added benchmark result.
benchmark code:
```
object LikeAnyBenchmark extends SqlBasedBenchmark {
import spark.implicits._
private val numRows = 10000
private val width = 5
def withTempTable(tableNames: String*)(f: => Unit): Unit = {
try f finally tableNames.foreach(spark.catalog.dropTempView)
}
private def saveAsTable(df: DataFrame, dir: File): Unit = {
val parquetPath = dir.getCanonicalPath + "/parquet"
df.write.mode("overwrite").parquet(parquetPath)
spark.read.parquet(parquetPath).createOrReplaceTempView("parquetTable")
}
override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
withTempPath { dir =>
withTempTable("parquetTable") {
val selectExpr = (1 to width).map(i => s"CAST(value + 1000000 AS STRING) c$i")
val df = spark.range(0, numRows, 1, 100)
.map(_ => Random.nextLong).selectExpr(selectExpr: _*)
saveAsTable(df, dir)
val benchmark =
new Benchmark("Multi like query", numRows, minNumIters = 3, output = output)
benchmark.addCase("Query with LikeAny simplification", numIters = 3) { _ =>
val likeAnyExpr =
Random.shuffle(Range(1000, 1300).map(i =>
if (i < 1100) s"'$i%'" else if (i < 1200) s"'%$i'" else s"'$i'"
)).mkString("c1 like any(", ", ", ")")
spark.sql(s"SELECT * FROM parquetTable WHERE $likeAnyExpr").noop()
}
benchmark.run()
}
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on a diff in pull request #38649: [SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards
Posted by GitBox <gi...@apache.org>.
wangyum commented on code in PR #38649:
URL: https://github.com/apache/spark/pull/38649#discussion_r1023546094
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -780,6 +780,13 @@ object LikeSimplification extends Rule[LogicalPlan] {
} else {
simplifyLike(input, pattern.toString, escapeChar).getOrElse(l)
}
+ case LikeAny(child, patterns)
+ if patterns.map(_.toString).forall { case equalTo(_) => true case _ => false } =>
+ InSet(child, patterns.toSet)
Review Comment:
Could we also support this case?
```sql
SELECT * FROM tab WHERE trim(addr) LIKE ANY ('5000', '5001', '5002%', '5003%', '5004')
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org