ganeshashree commented on code in PR #60336:
URL: https://github.com/apache/spark/pull/60336#discussion_r4565048525
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala:
##########
@@ -1715,22 +1715,17 @@ case class JsonArray(
// `RETURNING STRING`, which `DataTypeAstBuilder` maps to the companion.
(A non-default
// collation is not `==` to the companion anyway, since StringType.equals
compares constraint.)
val returningSQL = if (returning.eq(StringType)) "" else s" RETURNING
${returning.sql}"
+ // The non-default `NULL ON NULL` always renders. Canonical `sql`
(`forceBuiltinOwnership`) also
+ // appends the default `ABSENT ON NULL` so the reparse stays on the direct
grammar path instead
+ // of routing to a shadowing routine; the pretty form omits it to keep
column names clean.
+ // Mirrors `JsonObjectExpr`.
val nullSQL = nullBehavior match {
case JsonConstructorNullBehavior.Null => " NULL ON NULL"
- case JsonConstructorNullBehavior.Absent => ""
+ case JsonConstructorNullBehavior.Absent =>
+ if (forceBuiltinOwnership) " ABSENT ON NULL" else ""
}
- // Add `RETURNING STRING` so a clause-free render still means the built-in
when reparsed (a
- // clause-free call, even a nested one, could bind a shadow). A rendered
FORMAT JSON, null, or
- // RETURNING clause already does that.
- val rendersFormatJson = rendered.exists {
- case (v, isJson) => isJson && !directlyImplicit(v)
- }
- val ownershipClause =
- if (forceBuiltinOwnership && !rendersFormatJson && nullSQL.isEmpty &&
- returningSQL.isEmpty) {
- " RETURNING STRING"
- } else ""
- s"JSON_ARRAY($valuesSQL$nullSQL$returningSQL$ownershipClause)"
+ // `trim` drops the leading space when only a clause renders
(`JSON_ARRAY(ABSENT ON NULL)`).
+ s"JSON_ARRAY(${s"$valuesSQL$nullSQL$returningSQL".trim})"
Review Comment:
Thanks, good catch. Applied your suggestion: only a zero-element array drops
the leading space of its clauses, so value text stays verbatim. Added a test
that pins edge whitespace in column names (including `json_array(' ')` vs
`json_array()`) and the empty collated-RETURNING form.
--
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]