forked from databricks/spark-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor options to be managed in a single place.
Currently, there are a lot of options but they are not managed in a place. Just like `JSONOptions` (SPARK-11745) in Spark Datasource, this PR also makes this library manage the options in `XmlOptions` class and object. Author: hyukjinkwon <[email protected]> Closes databricks#50 from HyukjinKwon/separate-options.
- Loading branch information
1 parent
825f0ff
commit ff0d067
Showing
11 changed files
with
166 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2014 Databricks | ||
* | ||
* Licensed 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 com.databricks.spark.xml | ||
|
||
/** | ||
* Options for the XML data source. | ||
*/ | ||
private[xml] case class XmlOptions( | ||
charset: String = XmlOptions.DEFAULT_CHARSET, | ||
rowTag: String = XmlOptions.DEFAULT_ROW_TAG, | ||
rootTag: String = XmlOptions.DEFAULT_ROOT_TAG, | ||
samplingRatio: Double = 1.0, | ||
excludeAttributeFlag: Boolean = false, | ||
treatEmptyValuesAsNulls: Boolean = false, | ||
failFastFlag: Boolean = false, | ||
attributePrefix: String = XmlOptions.DEFAULT_ATTRIBUTE_PREFIX, | ||
valueTag: String = XmlOptions.DEFAULT_VALUE_TAG, | ||
nullValue: String = XmlOptions.DEFAULT_NULL_VALUE | ||
) | ||
|
||
private[xml] object XmlOptions { | ||
val DEFAULT_ATTRIBUTE_PREFIX = "@" | ||
val DEFAULT_VALUE_TAG = "#VALUE" | ||
val DEFAULT_ROW_TAG = "ROW" | ||
val DEFAULT_ROOT_TAG = "ROWS" | ||
val DEFAULT_CHARSET = "UTF-8" | ||
val DEFAULT_NULL_VALUE = "null" | ||
|
||
def createFromConfigMap(parameters: Map[String, String]): XmlOptions = XmlOptions( | ||
// TODO Support different encoding types. | ||
// TODO validate encoidng types. maybe with Charset.forname() | ||
charset = parameters.getOrElse("charset", DEFAULT_CHARSET), | ||
rowTag = parameters.getOrElse("rowTag", DEFAULT_ROW_TAG), | ||
rootTag = parameters.getOrElse("rootTag", DEFAULT_ROOT_TAG), | ||
samplingRatio = parameters.get("samplingRatio").map(_.toDouble).getOrElse(1.0), | ||
excludeAttributeFlag = parameters.get("excludeAttribute").map(_.toBoolean).getOrElse(false), | ||
treatEmptyValuesAsNulls = | ||
parameters.get("treatEmptyValuesAsNulls").map(_.toBoolean).getOrElse(false), | ||
failFastFlag = parameters.get("failFast").map(_.toBoolean).getOrElse(false), | ||
attributePrefix = parameters.getOrElse("attributePrefix", DEFAULT_ATTRIBUTE_PREFIX), | ||
valueTag = parameters.getOrElse("valueTag", DEFAULT_VALUE_TAG), | ||
nullValue = parameters.getOrElse("nullValue", DEFAULT_NULL_VALUE) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.