-
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
Changes from 7 commits
48d5a9f
05ab098
c769c40
ee94f98
4fa535b
2261433
cce5a55
4fd810a
cf2c243
98892fe
d0bade1
5b75d37
09f38f7
76639b7
f37f467
d5c2a40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ================================================================================================ | ||
| Benchmark trim the string | ||
| ================================================================================================ | ||
|
|
||
| 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 | ||
| Benchmark trim the string: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative | ||
| ------------------------------------------------------------------------------------------------------------------------ | ||
| cast(str as int) as c_int 6263 8132 NaN 1.3 764.6 1.0X | ||
| cast(str as long) as c_long 8199 9737 NaN 1.0 1000.9 0.8X | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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 = "Benchmark trim the string" | ||
| runBenchmark(title) { | ||
| withTempPath { dir => | ||
| val N = 500L << 14 | ||
| val df = spark.range(N) | ||
| val withoutWhitespace = "withoutWhitespace" | ||
| val withWhitespace = "withWhitespace" | ||
| // val types = Seq("int", "long", "float", "double", "decimal", "boolean") | ||
| val types = Seq("int", "long") | ||
|
|
||
| df.selectExpr(s"concat('${" " * 5}', id, '${" " * 5}') as str") | ||
|
||
| .write.mode("overwrite").parquet(dir.getCanonicalPath) | ||
| val benchmark = new Benchmark(title, N, minNumIters = 3, output = output) | ||
| types.foreach { t => | ||
| val expr = s"cast(str as $t) as c_$t" | ||
| benchmark.addCase(expr) { _ => | ||
| spark.read.parquet(dir.getCanonicalPath).selectExpr(expr).collect() | ||
| } | ||
| } | ||
| benchmark.run() | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another way is to embed the trim logic into
toInt.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check this