davidm-db commented on code in PR #60531:
URL: https://github.com/apache/spark/pull/60531#discussion_r4612082664
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala:
##########
@@ -1176,7 +1177,9 @@ case class MapObjects private(
// Make a copy of the data if it's unsafe-backed
def makeCopyIfInstanceOf(clazz: Class[_ <: Any], value: String) =
s"$value instanceof ${clazz.getSimpleName}? ${value}.copy() : $value"
- val genFunctionValue: String = lambdaFunction.dataType match {
+ // Resolve framework types so that struct-backed types are copied like a
StructType.
+ val genFunctionValue: String = TypeOps(lambdaFunction.dataType)
Review Comment:
[important] Unwrap UDTs in the collection-copy dispatch too.
The two sites in MapObjects and CatalystToExternalMap still look up the UDT
itself, so a lambda returning TestStructBackedUDT misses the representation and
all complex-copy branches. Using the new buffer-reuse tests with that wrapper
retains an UnsafeRow view: after the producer writes 2L, the retained list/map
value changes from 1L to 2L. Direct TestStructBackedType controls retain 1L.
Please unwrap sqlType before resolving TypeOps at both sites and add the UDT
variants. This is a remaining gap from the earlier PR revision that I missed in
the first review; UDTs over builtin structs have the same pre-existing
limitation.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InterpretedSafeProjection.scala:
##########
@@ -56,7 +57,12 @@ class InterpretedSafeProjection(expressions:
Seq[Expression]) extends Projection
(exprs(i), f)
}
- private def generateSafeValueConverter(dt: DataType): Any => Any = dt match {
+ // A framework type with a row representation is converted as that
representation.
+ private def generateSafeValueConverter(dt: DataType): Any => Any =
+
TypeOps(dt).flatMap(_.rowRepresentationType).map(generateSafeValueConverter)
Review Comment:
[important] Keep recursive interpreted safe conversion null-safe.
This newly routes TestStructBackedType (and a UDT over it) into the struct
converter, but nested nulls are passed through unguarded. With
ArrayType(TestStructBackedType(), containsNull = true) and [row, null],
interpreted safe projection throws NullPointerException at row.numFields;
generated safe projection preserves the null. Null map values and nullable
struct fields reproduce the same failure.
Please make recursive conversion preserve null before invoking the
representation converter and add these three shapes in both modes. The builtin
StructType converter already has this limitation; this change newly exposes it
for framework values.
--
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]