spark-test commented on code in PR #60706:
URL: https://github.com/apache/spark/pull/60706#discussion_r4626299735
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonParser.scala:
##########
@@ -238,7 +240,8 @@ class JacksonParser(
val fieldConverters = st.map(_.dataType).map(makeConverter).toArray
val res = try {
- convertObject(parser, st, fieldConverters)
+ convertObject(
+ parser, st, fieldConverters,
ResolveDefaultColumns.existenceDefaultValues(st))
Review Comment:
**Non-blocking (P2):** `ResolveDefaultColumns.existenceDefaultValues(st)` is
evaluated here, inside the per-record function, so when `from_json` reads a
bare JSON object under an array-of-struct schema, it re-analyzes the element's
existence defaults for every input row: one analysis instead of four, but still
one per row, not one per converter as the new `convertObject` Scaladoc says.
Because `fieldConverters` (line 240 of this file) is rebuilt for every record
too, structs nested in the element get fresh converters whose lazily cached
defaults are re-analyzed per row as well. Results are unchanged; the cost is
CPU proportional to rows times defaulted fields, and an `EXISTS_DEFAULT` that
needs fallback resolution logs its warning once per row. Only `from_json` with
an array-of-struct schema whose fields carry `EXISTS_DEFAULT` reaches this
case; the JSON data source reads through the struct-root converter, which this
PR fixes.
`makeArrayRootConverter` already builds `elemConverter` once per parser, and
for a struct element it is exactly the struct converter with cached field
converters and lazy defaults, which makes this same `convertObject` call (no
filters, not as a root). Converting the object with
`elemConverter.apply(parser)` inside the same `try`/`catch`, and wrapping the
returned row in a one-element `GenericArrayData`, would remove both the
per-record rebuild and the per-record analysis without adding state.
**Verification:**
- **Behavior:** Parsing several rows with one parser for an array-of-struct
schema whose element struct, and a struct nested in that element, each have a
field with an existence default returns those defaults for every row whose JSON
is a single object lacking the fields, the parsed values for a row that has
them, and the same arrays as before for rows whose JSON is an array.
- **Regression:** The existing tests of a bare JSON object read under an
array-of-struct schema still pass: JsonExpressionsSuite's 'from_json -
input=object, schema=array, output=array of single row' and 'from_json -
input=empty object, schema=array, output=array of single row with null', and
JsonFunctionsSuite's 'SPARK-48863: parse object as an array with partial
results enabled'.
- **Inspection:** The per-record function that
JacksonParser.makeArrayRootConverter returns no longer builds field converters
or calls ResolveDefaultColumns.existenceDefaultValues; its single-object case
converts with elemConverter inside the same try/catch.
--
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]