[SPARK-49193][SQL] Improve the performance of RowSetUtils.toColumnBasedSet#47699
Closed
wangyum wants to merge 3 commits intoapache:masterfrom
Closed
[SPARK-49193][SQL] Improve the performance of RowSetUtils.toColumnBasedSet#47699wangyum wants to merge 3 commits intoapache:masterfrom
wangyum wants to merge 3 commits intoapache:masterfrom
Conversation
HyukjinKwon
reviewed
Aug 11, 2024
| val values = new java.util.ArrayList[String](rowSize) | ||
| while (i < rowSize) { | ||
| val row = rows(i) | ||
| rows.foreach { row => |
Member
There was a problem hiding this comment.
Hmmm generally while is faster than foreach (https://github.com/databricks/scala-style-guide?tab=readme-ov-file#traversal-and-zipwithindex)
Member
Author
There was a problem hiding this comment.
It seems the Array's performance is much better than Seq.
toColumnBasedSet time: 138, toRowBasedSet time: 73
yaooqinn
approved these changes
Aug 11, 2024
Member
Author
|
Another test: import org.apache.hive.service.rpc.thrift.TProtocolVersion
import org.apache.spark.sql.execution.HiveResult
val df = spark.sql("select id, cast(id as string), cast(id as timestamp), cast(id as decimal(18, 0)) from range(20000000)")
val dataTypes = df.schema.fields.map(_.dataType)
val rows = df.collect().toList
val start1 = System.currentTimeMillis()
RowSetUtils.toTRowSet(1, rows, dataTypes,
TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11, HiveResult.getTimeFormatters)
val start2 = System.currentTimeMillis()
RowSetUtils.toTRowSet(1, rows, dataTypes,
TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V5, HiveResult.getTimeFormatters)
val start3 = System.currentTimeMillis()
println(s"toColumnBasedSet time: ${start2 - start1}, toRowBasedSet time: ${start3 - start2}")Result: |
HyukjinKwon
approved these changes
Aug 11, 2024
Member
|
The docmumentation build, you might need to sync your branch and master branch to the latest. Merged to master. |
yaooqinn
pushed a commit
that referenced
this pull request
Aug 12, 2024
…edSet ### What changes were proposed in this pull request? Replace `while` loop with `foreach` in `RowSetUtils.toTColumn`. ### Why are the changes needed? Improve the performance of `RowSetUtils.toColumnBasedSet`: <img width="1196" alt="image" src="https://github.com/user-attachments/assets/f481de39-e0bf-41c5-8fee-09dc1a93c4e1"> ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Manual test. ```scala import org.apache.hive.service.rpc.thrift.TProtocolVersion import org.apache.spark.sql.execution.HiveResult val df = spark.sql("select id, cast(id as string), cast(id as timestamp) from range(200000)") val dataTypes = df.schema.fields.map(_.dataType) val rows = df.collect().toList val start1 = System.currentTimeMillis() RowSetUtils.toTRowSet(1, rows, dataTypes, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11, HiveResult.getTimeFormatters) val start2 = System.currentTimeMillis() RowSetUtils.toTRowSet(1, rows, dataTypes, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V5, HiveResult.getTimeFormatters) val start3 = System.currentTimeMillis() println(s"toColumnBasedSet time: ${start2 - start1}, toRowBasedSet time: ${start3 - start2}") ``` Before this PR: ``` toColumnBasedSet time: 17307, toRowBasedSet time: 71 ``` After this PR: ``` toColumnBasedSet time: 128, toRowBasedSet time: 70 ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #47699 from wangyum/toColumnBasedSet. Authored-by: Yuming Wang <yumwang@ebay.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org> (cherry picked from commit 567d58c) Signed-off-by: Kent Yao <yao@apache.org>
yaooqinn
pushed a commit
that referenced
this pull request
Aug 12, 2024
…edSet ### What changes were proposed in this pull request? Replace `while` loop with `foreach` in `RowSetUtils.toTColumn`. ### Why are the changes needed? Improve the performance of `RowSetUtils.toColumnBasedSet`: <img width="1196" alt="image" src="https://github.com/user-attachments/assets/f481de39-e0bf-41c5-8fee-09dc1a93c4e1"> ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Manual test. ```scala import org.apache.hive.service.rpc.thrift.TProtocolVersion import org.apache.spark.sql.execution.HiveResult val df = spark.sql("select id, cast(id as string), cast(id as timestamp) from range(200000)") val dataTypes = df.schema.fields.map(_.dataType) val rows = df.collect().toList val start1 = System.currentTimeMillis() RowSetUtils.toTRowSet(1, rows, dataTypes, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11, HiveResult.getTimeFormatters) val start2 = System.currentTimeMillis() RowSetUtils.toTRowSet(1, rows, dataTypes, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V5, HiveResult.getTimeFormatters) val start3 = System.currentTimeMillis() println(s"toColumnBasedSet time: ${start2 - start1}, toRowBasedSet time: ${start3 - start2}") ``` Before this PR: ``` toColumnBasedSet time: 17307, toRowBasedSet time: 71 ``` After this PR: ``` toColumnBasedSet time: 128, toRowBasedSet time: 70 ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #47699 from wangyum/toColumnBasedSet. Authored-by: Yuming Wang <yumwang@ebay.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org> (cherry picked from commit 567d58c) Signed-off-by: Kent Yao <yao@apache.org>
Member
|
I backported this to branch-3.5 and branch-3.4 |
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?
Replace
whileloop withforeachinRowSetUtils.toTColumn.Why are the changes needed?
Improve the performance of

RowSetUtils.toColumnBasedSet:Does this PR introduce any user-facing change?
No.
How was this patch tested?
Manual test.
Before this PR:
After this PR:
Was this patch authored or co-authored using generative AI tooling?
No.