dejankrak-db commented on code in PR #60531:
URL: https://github.com/apache/spark/pull/60531#discussion_r4588396346


##########
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:
   Done in a6ba089e2bc: `InterpretedSafeProjection` now converts a framework 
type as its row representation, and `InternalRow.getWriter`, which the 
interpreted safe and mutable projections use, writes it as its representation, 
so the value is copied. The suite runs the safe and mutable projections in both 
modes on a reused `UnsafeRow`, and the result keeps its value after the buffer 
is overwritten.



##########
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:
   Done in a6ba089e2bc: the UDT branches of `getElementSize`, `setColumn` and 
`convertToSafe` now re-enter the resolving helper, and `addBufferedState` and 
`canSupport` unwrap the UDT before the lookup. The suite covers a UDT over the 
test type in the safe and mutable projections and in an array round trip, each 
in both modes, and in `canSupport` and `addBufferedState`.



-- 
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]

Reply via email to