You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2017/12/08 06:49:09 UTC
spark git commit: [SPARK-22452][SQL] Add getDouble to
DataSourceV2Options
Repository: spark
Updated Branches:
refs/heads/master b11869bc3 -> f88a67bf0
[SPARK-22452][SQL] Add getDouble to DataSourceV2Options
- Implemented getDouble method in DataSourceV2Options
- Add unit test
Author: Sunitha Kambhampati <sk...@us.ibm.com>
Closes #19921 from skambha/ds2.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/f88a67bf
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/f88a67bf
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/f88a67bf
Branch: refs/heads/master
Commit: f88a67bf08a66bd0291c11776a0c7c3928738ed9
Parents: b11869b
Author: Sunitha Kambhampati <sk...@us.ibm.com>
Authored: Fri Dec 8 14:48:19 2017 +0800
Committer: Wenchen Fan <we...@databricks.com>
Committed: Fri Dec 8 14:48:19 2017 +0800
----------------------------------------------------------------------
.../apache/spark/sql/sources/v2/DataSourceV2Options.java | 9 +++++++++
.../spark/sql/sources/v2/DataSourceV2OptionsSuite.scala | 11 +++++++++++
2 files changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/f88a67bf/sql/core/src/main/java/org/apache/spark/sql/sources/v2/DataSourceV2Options.java
----------------------------------------------------------------------
diff --git a/sql/core/src/main/java/org/apache/spark/sql/sources/v2/DataSourceV2Options.java b/sql/core/src/main/java/org/apache/spark/sql/sources/v2/DataSourceV2Options.java
index b2c908d..e98c045 100644
--- a/sql/core/src/main/java/org/apache/spark/sql/sources/v2/DataSourceV2Options.java
+++ b/sql/core/src/main/java/org/apache/spark/sql/sources/v2/DataSourceV2Options.java
@@ -80,4 +80,13 @@ public class DataSourceV2Options {
Long.parseLong(keyLowerCasedMap.get(lcaseKey)) : defaultValue;
}
+ /**
+ * Returns the double value to which the specified key is mapped,
+ * or defaultValue if there is no mapping for the key. The key match is case-insensitive
+ */
+ public double getDouble(String key, double defaultValue) {
+ String lcaseKey = toLowerCase(key);
+ return keyLowerCasedMap.containsKey(lcaseKey) ?
+ Double.parseDouble(keyLowerCasedMap.get(lcaseKey)) : defaultValue;
+ }
}
http://git-wip-us.apache.org/repos/asf/spark/blob/f88a67bf/sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2OptionsSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2OptionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2OptionsSuite.scala
index 752d3c1..90d9286 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2OptionsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2OptionsSuite.scala
@@ -68,4 +68,15 @@ class DataSourceV2OptionsSuite extends SparkFunSuite {
options.getLong("foo", 0L)
}
}
+
+ test("getDouble") {
+ val options = new DataSourceV2Options(Map("numFoo" -> "922337.1",
+ "foo" -> "bar").asJava)
+ assert(options.getDouble("numFOO", 0d) == 922337.1d)
+ assert(options.getDouble("numFoo2", -1.02d) == -1.02d)
+
+ intercept[NumberFormatException]{
+ options.getDouble("foo", 0.1d)
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org