You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhenlineo (via GitHub)" <gi...@apache.org> on 2023/05/23 15:41:22 UTC

[GitHub] [spark] zhenlineo commented on a diff in pull request #41264: [SPARK-43717][CONNECT] Scala client reduce agg cannot handle null partitions for scala primitive inputs

zhenlineo commented on code in PR #41264:
URL: https://github.com/apache/spark/pull/41264#discussion_r1202570122


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala:
##########
@@ -154,6 +154,17 @@ object ScalaReflection extends ScalaReflection {
     case _ => "array"
   }
 
+  private[sql] def defaultValueFor(enc: AgnosticEncoder[_]): Any = enc match {
+      case PrimitiveBooleanEncoder => null.asInstanceOf[Boolean]
+      case PrimitiveByteEncoder => null.asInstanceOf[Byte]
+      case PrimitiveShortEncoder => null.asInstanceOf[Short]
+      case PrimitiveIntEncoder => null.asInstanceOf[Int]
+      case PrimitiveLongEncoder => null.asInstanceOf[Long]
+      case PrimitiveFloatEncoder => null.asInstanceOf[Float]
+      case PrimitiveDoubleEncoder => null.asInstanceOf[Double]
+      case _ => null

Review Comment:
   `null.asInstanceOf[Boolean]` will return false. The problem with ReduceAggregator was the type T was considered of type Encoder, so even if T is a Boolean during runtime, we receive `b = null`, which causes the NPE. So I have to enforce the cast here during compilation based on the encoder to correct the default value.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org