Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ public long getLong(String key, long defaultValue) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}