srielau commented on code in PR #58130:
URL: https://github.com/apache/spark/pull/58130#discussion_r3836572568
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/jsonExpressions.scala:
##########
@@ -265,8 +265,12 @@ case class MultiGetJsonObject(
// scalastyle:on line.size.limit line.contains.tab
case class JsonTuple(children: Seq[Expression])
extends Generator
+ with ExpectsInputTypes
Review Comment:
Fixed in 4132d659450. `JsonTuple` no longer mixes `ExpectsInputTypes`; it
has a dedicated `ImplicitTypeCoercion` arm that applies only
`charVarcharToPlainString`. Added rule tests proving INT and untyped NULL
children remain unchanged while CHAR children become STRING.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionHelper.scala:
##########
@@ -651,14 +716,20 @@ abstract class TypeCoercionHelper {
case e: ExpectsInputTypes if e.inputTypes.nonEmpty =>
// Convert NullType into some specific target type for
ExpectsInputTypes that don't do
- // general implicit casting.
+ // general implicit casting. Also promote CHAR/VARCHAR to STRING here:
these
+ // expressions skip ImplicitCastInputTypes, so without this the length
constraint would
+ // remain on the child.
val children: Seq[Expression] = e.children.zip(e.inputTypes).map {
case (in, expected) =>
- if (in.dataType == NullType && !expected.acceptsType(NullType)) {
- Literal.create(null, expected.defaultConcreteType)
- } else {
- in
- }
+ charVarcharToPlainString(in.dataType, expected)
+ .map(dt => if (dt == in.dataType) in else Cast(in, dt))
+ .getOrElse {
+ if (in.dataType == NullType &&
!expected.acceptsType(NullType)) {
+ Literal.create(null, expected.defaultConcreteType)
Review Comment:
Fixed. The dedicated `JsonTuple` arm now runs before the generic
`ExpectsInputTypes` arm and does not perform the NullType rewrite. The PR
description has also been updated to match the implementation.
--
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]