-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28023][SQL] Add trim logic in UTF8String's toInt/toLong to make it consistent with other string-numeric casting #26622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
48d5a9f
[WIP][SPARK-28023][Test] Cheap UTF8String Trim
yaooqinn 05ab098
benchmark without trim
yaooqinn c769c40
benchmark without trim
yaooqinn ee94f98
benchmark with copy trim
yaooqinn 4fa535b
benchmark with non copy trim
yaooqinn 2261433
benchmark with non copy trim r2
yaooqinn cce5a55
benchmark with copy trim r2
yaooqinn 4fd810a
inside trim
yaooqinn cf2c243
rm left spaces
yaooqinn 98892fe
trim v.s inside trim
yaooqinn d0bade1
method local
yaooqinn 5b75d37
benchmark
yaooqinn 09f38f7
fix bug and benchmark
yaooqinn 76639b7
clean benchmark
yaooqinn f37f467
control chars
yaooqinn d5c2a40
m guide
yaooqinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ================================================================================================ | ||
| Cast String to Numeric | ||
| ================================================================================================ | ||
|
|
||
| Java HotSpot(TM) 64-Bit Server VM 1.8.0_231-b11 on Mac OS X 10.15.1 | ||
| Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz | ||
| Cast String to Numeric: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative | ||
| ------------------------------------------------------------------------------------------------------------------------ | ||
| cast(trim(str) as int) as c_int 6559 9435 NaN 1.2 800.6 1.0X | ||
| cast(trim(str) as long) as c_long 6841 9341 1416 1.2 835.1 1.0X | ||
|
|
||
| Java HotSpot(TM) 64-Bit Server VM 1.8.0_231-b11 on Mac OS X 10.15.1 | ||
| Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz | ||
| Cast String to Numeric: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative | ||
| ------------------------------------------------------------------------------------------------------------------------ | ||
| cast(trim(str) as int) as c_int 4259 5270 1110 1.9 519.9 1.0X | ||
| cast(trim(str) as long) as c_long 4081 5663 1372 2.0 498.2 1.0X | ||
| cast(str as int) as c_int 4071 4254 176 2.0 496.9 1.0X | ||
| cast(str as long) as c_long 4121 5087 1272 2.0 503.1 1.0X | ||
|
|
||
|
|
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
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
59 changes: 59 additions & 0 deletions
59
sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/CastBenchmark.scala
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.execution.benchmark | ||
|
|
||
| import org.apache.spark.benchmark.Benchmark | ||
|
|
||
| /** | ||
| * Benchmark trim the string when casting string type to Boolean/Numeric types. | ||
| * To run this benchmark: | ||
| * {{{ | ||
| * 1. without sbt: | ||
| * bin/spark-submit --class <this class> --jars <spark core test jar> <spark sql test jar> | ||
| * 2. build/sbt "sql/test:runMain <this class>" | ||
| * 3. generate result: SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "sql/test:runMain <this class>" | ||
| * Results will be written to "benchmarks/CastBenchmark-results.txt". | ||
| * }}} | ||
| */ | ||
| object CastBenchmark extends SqlBasedBenchmark { | ||
yaooqinn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| override def runBenchmarkSuite(mainArgs: Array[String]): Unit = { | ||
|
|
||
| val title = "Cast String to Integral" | ||
| runBenchmark(title) { | ||
| withTempPath { dir => | ||
| val N = 500L << 14 | ||
| val df = spark.range(N) | ||
| val types = Seq("int", "long") | ||
| df.selectExpr(s"concat(id, '${" " * 5}') as str") | ||
| .write.mode("overwrite").parquet(dir.getCanonicalPath) | ||
| val benchmark = new Benchmark(title, N, minNumIters = 5, output = output) | ||
| Seq(true, false).foreach { c => | ||
| types.foreach { t => | ||
| val str = if (c) "trim(str)" else "str" | ||
| val expr = s"cast($str as $t) as c_$t" | ||
| benchmark.addCase(expr) { _ => | ||
| spark.read.parquet(dir.getCanonicalPath).selectExpr(expr).collect() | ||
| } | ||
| } | ||
| benchmark.run() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.