davidm-db commented on code in PR #60531:
URL: https://github.com/apache/spark/pull/60531#discussion_r4584321880
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InterpretedUnsafeProjection.scala:
##########
@@ -305,13 +306,16 @@ object InterpretedUnsafeProjection {
* portion of the array object. Primitives take up to 8 bytes, depending on
the size of the
* underlying data type.
*/
+ private def getElementSize(dataType: DataType): Int =
+
TypeOps(dataType).map(_.getElementSize).getOrElse(getElementSizeDefault(dataType))
+
@scala.annotation.tailrec
- private def getElementSize(dataType: DataType): Int = dataType match {
+ private def getElementSizeDefault(dataType: DataType): Int = dataType match {
case NullType | _: StringType | BinaryType | CalendarIntervalType |
VariantType |
_: AnyTimestampNanoType |
_: DecimalType | _: StructType | _: ArrayType | _: MapType => 8
case udt: UserDefinedType[_] =>
- getElementSize(udt.sqlType)
+ getElementSizeDefault(udt.sqlType)
Review Comment:
[important] Re-enter framework dispatch after unwrapping a UDT.
For a UserDefinedType whose sqlType is TestStructBackedType, this call
bypasses the declared getElementSize of 8 and falls back to defaultSize, which
is 20. The interpreted writer then places array pointer slots 20 bytes apart,
while UnsafeArrayData.getStruct reads them eight bytes apart. In a two-element
round-trip repro, generated projection reads values 1L and 2L correctly, but
interpreted projection reads 240518168608L for the second value.
Please normalize UDTs before the ops lookup, or re-enter the resolving
helper after unwrapping. Audit the corresponding bypasses in setColumnDefault,
convertToSafeDefault, addBufferedState and canSupport; canSupport currently
rejects the same wrapper. Add UDT-wrapped projection regression cases.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateSafeProjection.scala:
##########
@@ -136,15 +137,22 @@ object GenerateSafeProjection extends
CodeGenerator[Seq[Expression], Projection]
ExprCode(code, FalseLiteral, JavaCode.variable(output, classOf[MapData]))
}
- @tailrec
private def convertToSafe(
+ ctx: CodegenContext,
+ input: ExprValue,
+ dataType: DataType): ExprCode =
+ TypeOps(dataType).flatMap(_.rowRepresentationType).map(convertToSafe(ctx,
input, _))
Review Comment:
[important] Complete interpreted projection ownership/conversion too.
This resolves the generated converter, but the interpreted safe converter
still returns identity for TestStructBackedType, and its framework row writer
stores the UnsafeRow reference. SafeProjection selects this implementation
under NO_CODEGEN or codegen fallback. In a focused repro, the nested result is
still an UnsafeRow and its value changes from 1L to 2L when the unsafe producer
writes the next row; generated safe projection preserves 1L.
Please add representation-aware conversion and consistent ownership to the
interpreted paths, and test both modes with reused unsafe input.
InterpretedMutableProjection uses the same direct framework writer, so its
ownership case needs coverage too. This needs to be settled before enabling the
first complex-backed production type.
--
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]