[SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards#38649
Closed
wankunde wants to merge 3 commits intoapache:masterfrom
Closed
[SPARK-41132][SQL] Convert LikeAny and NotLikeAny to InSet if no pattern contains wildcards#38649wankunde wants to merge 3 commits intoapache:masterfrom
wankunde wants to merge 3 commits intoapache:masterfrom
Conversation
|
Can one of the admins verify this patch? |
wangyum
reviewed
Nov 16, 2022
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
Outdated
Show resolved
Hide resolved
…ern contains wildcards
…ern contains wildcards
wangyum
reviewed
Dec 8, 2022
| if (remainPatterns.nonEmpty) And(and, l.copy(patterns = remainPatterns)) else and | ||
| case l: LikeAny => | ||
| val or = buildBalancedPredicate(replacements, Or) | ||
| val equalPatterns = MutableHashset[Any]() |
Member
There was a problem hiding this comment.
Do you have some benchmark number?
Contributor
Author
There was a problem hiding this 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()
}
}
}
}
|
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. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
Improve likeAny and notLikeAny performance.
We can optimize query
SELECT * FROM tab WHERE trim(addr) LIKE ANY ('5001', '5002%', '%5003', '5004', '5001')toSELECT * FROM tab WHERE trim(addr) IN ('5001', '5004') OR trim(addr) like '5002%' OR trim(addr) like '%5003'Before this PR
After this PR
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