-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-26310][SQL] Verify applicability of JSON options #23257
Changes from 4 commits
edbe0b7
af15070
9ee62ac
06a0df1
e1db3ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,14 @@ import com.fasterxml.jackson.core.{JsonFactory, JsonParser} | |
|
||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.sql.catalyst.util._ | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
||
/** | ||
* Options for parsing JSON data into Spark SQL rows. | ||
* | ||
* Most of these map directly to Jackson's internal options, specified in [[JsonParser.Feature]]. | ||
*/ | ||
private[sql] class JSONOptions( | ||
private[sql] abstract class JSONOptions( | ||
@transient val parameters: CaseInsensitiveMap[String], | ||
defaultTimeZoneId: String, | ||
defaultColumnNameOfCorruptRecord: String) | ||
|
@@ -128,6 +129,17 @@ private[sql] class JSONOptions( | |
allowBackslashEscapingAnyCharacter) | ||
factory.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, allowUnquotedControlChars) | ||
} | ||
|
||
def notApplicableOptions: Set[String] | ||
def checkOptions(where: String): Unit = { | ||
val wrongOptions = notApplicableOptions.filter(parameters.contains(_)) | ||
if (!wrongOptions.isEmpty && SQLConf.get.verifyDataSourceOptions) { | ||
// scalastyle:off throwerror | ||
throw new IllegalArgumentException( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also consider to warn when |
||
s"""The JSON options are not applicable $where : ${wrongOptions.mkString(", ")}.""") | ||
// scalastyle:on throwerror | ||
} | ||
} | ||
} | ||
|
||
private[sql] class JSONOptionsInRead( | ||
|
@@ -158,6 +170,11 @@ private[sql] class JSONOptionsInRead( | |
|
||
enc | ||
} | ||
|
||
override def notApplicableOptions: Set[String] = Set( | ||
"compression", | ||
"pretty") | ||
checkOptions("in read") | ||
} | ||
|
||
private[sql] object JSONOptionsInRead { | ||
|
@@ -172,3 +189,34 @@ private[sql] object JSONOptionsInRead { | |
Charset.forName("UTF-32") | ||
) | ||
} | ||
|
||
private[sql] class JSONOptionsInWrite( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't also need |
||
@transient override val parameters: CaseInsensitiveMap[String], | ||
defaultTimeZoneId: String) | ||
extends JSONOptions(parameters, defaultTimeZoneId, "") { | ||
|
||
def this( | ||
parameters: Map[String, String], | ||
defaultTimeZoneId: String) = { | ||
this( | ||
CaseInsensitiveMap(parameters), | ||
defaultTimeZoneId) | ||
} | ||
|
||
override def notApplicableOptions: Set[String] = Set( | ||
"samplingRatio", | ||
"primitivesAsString", | ||
"prefersDecimal", | ||
"allowComments", | ||
"allowUnquotedFieldNames", | ||
"allowSingleQuotes", | ||
"allowNumericLeadingZeros", | ||
"allowNonNumericNumbers", | ||
"allowBackslashEscapingAnyCharacter", | ||
"allowUnquotedControlChars", | ||
"mode", | ||
"columnNameOfCorruptRecord", | ||
"dropFieldIfAllNull", | ||
"multiLine") | ||
checkOptions("in write") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1635,6 +1635,14 @@ object SQLConf { | |
"java.time.* packages are used for the same purpose.") | ||
.booleanConf | ||
.createWithDefault(false) | ||
|
||
val VERIFY_DATASOURCE_OPTIONS = buildConf("spark.sql.verifyDataSourceOptions") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a config for this? seems more like a bug fix, even if it's a behavior change, and we can be stricter about validation in Spark 3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove the config but @gatorsmile asked to add it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I can't say I feel too strongly about it, but when would this be set to |
||
.doc("Options passed to datasource are checked that rather they could be applied in read or " + | ||
"in write when this configuration property is set to true. For example, If an option can " + | ||
"be applied only in read but applied in write, an exception is raised. " + | ||
"To disable the verification, set it to false.") | ||
.booleanConf | ||
.createWithDefault(true) | ||
} | ||
|
||
/** | ||
|
@@ -1820,6 +1828,8 @@ class SQLConf extends Serializable with Logging { | |
|
||
def fastHashAggregateRowMaxCapacityBit: Int = getConf(FAST_HASH_AGGREGATE_MAX_ROWS_CAPACITY_BIT) | ||
|
||
def verifyDataSourceOptions: Boolean = getConf(VERIFY_DATASOURCE_OPTIONS) | ||
|
||
/** | ||
* Returns the [[Resolver]] for the current configuration, which can be used to determine if two | ||
* identifiers are equal. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need this.