HyukjinKwon commented on a change in pull request #23349: [SPARK-26403][SQL]
Support pivoting using array column for `pivot(column)` API
URL: https://github.com/apache/spark/pull/23349#discussion_r243877485
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
##########
@@ -67,6 +67,7 @@ object Literal {
case t: Timestamp => Literal(DateTimeUtils.fromJavaTimestamp(t),
TimestampType)
case d: Date => Literal(DateTimeUtils.fromJavaDate(d), DateType)
case a: Array[Byte] => Literal(a, BinaryType)
+ case a: collection.mutable.WrappedArray[_] => apply(a.array)
Review comment:
That wouldn't work
```scala
scala> Array(1,2,3).asInstanceOf[Array[Any]]
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
... 29 elided
scala> classOf[Array[Any]].getComponentType()
res1: Class[_] = class java.lang.Object
```
The cases below fail to compile.
```scala
apply(a.toArray[classTag[Any]])
apply(a.toArray[scala.reflect.classTag[Any]])
```
The case below causes runtime failure.
```scala
case a: Seq[Any] => apply(a.toArray)
```
```
Unsupported component type class java.lang.Object in arrays;
org.apache.spark.sql.AnalysisException: Unsupported component type class
java.lang.Object in arrays;
at
org.apache.spark.sql.catalyst.expressions.Literal$.componentTypeToDataType(literals.scala:119)
at
org.apache.spark.sql.catalyst.expressions.Literal$.apply(literals.scala:72)
at
org.apache.spark.sql.RelationalGroupedDataset.$anonfun$pivot$2(RelationalGroupedDataset.scala:427)
at
scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
at
scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
at
scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:39)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]