cfmcgrady commented on a change in pull request #33212:
URL: https://github.com/apache/spark/pull/33212#discussion_r668378236
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonParser.scala
##########
@@ -418,6 +426,19 @@ class JacksonParser(
}
}
+ // When the input schema is setting to `nullable = false`, make sure the
field is not null.
+ var index = 0
+ while (badRecordException.isEmpty && !skipRow && index < schema.length) {
+ if (!schema(index).nullable && row.isNullAt(index)) {
+ throw new IllegalSchemaArgumentException(
+ s"the null value found when parsing non-nullable field
${schema(index).name}.")
+ }
+ if (!checkedIndexSet.contains(index)) {
+ skipRow = structFilters.skipRow(row, index)
Review comment:
For example:
```scala
val missingFieldInput = """{"c1":1}"""
val schema = StructType(Seq(
StructField("c1", IntegerType, nullable = true),
StructField("c2", IntegerType, nullable = true)
))
val filters = Seq(IsNotNull("c2"))
val options = new JSONOptions(Map.empty[String, String], "GMT", "")
val parser = new JacksonParser(schema, options, false, filters)
val createParser = CreateJacksonParser.string _
val result = parser.parse(missingFieldInput, createParser,
UTF8String.fromString)
println(result)
```
before this pr:
```
List([1,null])
```
after this pr:
```
List()
```
Please let me know if I've missed out anything.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]