You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by li...@apache.org on 2017/06/13 17:12:32 UTC
spark git commit: [SPARK-21016][CORE] Improve code fault tolerance
for converting string to number
Repository: spark
Updated Branches:
refs/heads/master bcf3643f9 -> 7ba8bf288
[SPARK-21016][CORE] Improve code fault tolerance for converting string to number
## What changes were proposed in this pull request?
When converting `string` to `number`(int, long or double), if the string has a space before or after,will lead to unnecessary mistakes.
## How was this patch tested?
unit test
Author: liuxian <li...@zte.com.cn>
Closes #18238 from 10110346/lx-wip-0608.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/7ba8bf28
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/7ba8bf28
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/7ba8bf28
Branch: refs/heads/master
Commit: 7ba8bf288de721d897c8ea23ed01cb2adc32df80
Parents: bcf3643
Author: liuxian <li...@zte.com.cn>
Authored: Tue Jun 13 10:12:28 2017 -0700
Committer: Xiao Li <ga...@gmail.com>
Committed: Tue Jun 13 10:12:28 2017 -0700
----------------------------------------------------------------------
.../scala/org/apache/spark/internal/config/ConfigBuilder.scala | 4 ++--
.../scala/org/apache/spark/sql/internal/SQLConfEntrySuite.scala | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/7ba8bf28/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala b/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala
index 515c9c2..8f4c1b6 100644
--- a/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala
+++ b/core/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala
@@ -28,7 +28,7 @@ private object ConfigHelpers {
def toNumber[T](s: String, converter: String => T, key: String, configType: String): T = {
try {
- converter(s)
+ converter(s.trim)
} catch {
case _: NumberFormatException =>
throw new IllegalArgumentException(s"$key should be $configType, but was $s")
@@ -37,7 +37,7 @@ private object ConfigHelpers {
def toBoolean(s: String, key: String): Boolean = {
try {
- s.toBoolean
+ s.trim.toBoolean
} catch {
case _: IllegalArgumentException =>
throw new IllegalArgumentException(s"$key should be boolean, but was $s")
http://git-wip-us.apache.org/repos/asf/spark/blob/7ba8bf28/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfEntrySuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfEntrySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfEntrySuite.scala
index f2456c7..135370b 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfEntrySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfEntrySuite.scala
@@ -37,6 +37,9 @@ class SQLConfEntrySuite extends SparkFunSuite {
assert(conf.getConfString(key) === "20")
assert(conf.getConf(confEntry, 5) === 20)
+ conf.setConfString(key, " 20")
+ assert(conf.getConf(confEntry, 5) === 20)
+
val e = intercept[IllegalArgumentException] {
conf.setConfString(key, "abc")
}
@@ -75,6 +78,8 @@ class SQLConfEntrySuite extends SparkFunSuite {
assert(conf.getConfString(key) === "true")
assert(conf.getConf(confEntry, false) === true)
+ conf.setConfString(key, " true ")
+ assert(conf.getConf(confEntry, false) === true)
val e = intercept[IllegalArgumentException] {
conf.setConfString(key, "abc")
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org