Skip to content

Commit

Permalink
Make some required parameters optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nightscape committed Aug 16, 2017
1 parent deea119 commit 446e747
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
0.8.6
=====
- Change: Some previously required parameters are now optional and have a default

0.8.5
=====
- Feature: Respecting user-provided schema
- Bugfix: Several fixes to parsing
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ val sqlContext = new SQLContext(sc)
val df = sqlContext.read
.format("com.crealytics.spark.excel")
.option("location", "Worktime.xlsx")
.option("sheetName", "Daily")
.option("useHeader", "true")
.option("treatEmptyValuesAsNulls", "true")
.option("inferSchema", "true")
.option("addColorColumns", "true")
.option("startColumn", 0) // Optional
.option("endColumn", 99) // Optional
.schema(myCustomSchema) // Optional
.load()
.option("sheetName", "Daily") // Required
.option("useHeader", "true") // Required
.option("treatEmptyValuesAsNulls", "false") // Optional, default: true
.option("inferSchema", "false") // Optional, default: false
.option("addColorColumns", "true") // Optional, default: false
.option("startColumn", 0) // Optional, default: 0
.option("endColumn", 99) // Optional, default: Int.MaxValue
.schema(myCustomSchema) // Optional, default: Either inferred schema, or all columns are Strings
```

## Building From Source
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/com/crealytics/spark/excel/DefaultSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class DefaultSource
location = checkParameter(parameters, "location"),
sheetName = parameters.get("sheetName"),
useHeader = checkParameter(parameters, "useHeader").toBoolean,
treatEmptyValuesAsNulls = checkParameter(parameters, "treatEmptyValuesAsNulls").toBoolean,
treatEmptyValuesAsNulls = parameters.get("treatEmptyValuesAsNulls").fold(true)(_.toBoolean),
userSchema = Option(schema),
inferSheetSchema = checkParameter(parameters, "inferSchema").toBoolean,
addColorColumns = checkParameter(parameters, "addColorColumns").toBoolean,
inferSheetSchema = parameters.get("inferSchema").fold(false)(_.toBoolean),
addColorColumns = parameters.get("addColorColumns").fold(false)(_.toBoolean),
startColumn = parameters.get("startColumn").fold(0)(_.toInt),
endColumn = parameters.get("endColumn").fold(Int.MaxValue)(_.toInt)
)(sqlContext)
}

// Forces a Parameter to exist, otherwise an exception is thrown.
private def checkParameter(map: Map[String, String], param: String) = {
private def checkParameter(map: Map[String, String], param: String): String = {
if (!map.contains(param)) {
throw new IllegalArgumentException(s"Parameter ${'"'}$param${'"'} is missing in options.")
} else {
Expand Down

0 comments on commit 446e747

Please sign in to comment.