This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new b35e61f83ff9 [SPARK-46604][SQL] Make `Literal.apply` support 
`s.c.immuable.ArraySeq`
b35e61f83ff9 is described below

commit b35e61f83ff9a98300533ae8c88c313d9ccdbf86
Author: yangjie01 <yangji...@baidu.com>
AuthorDate: Sat Jan 6 12:51:13 2024 -0800

    [SPARK-46604][SQL] Make `Literal.apply` support `s.c.immuable.ArraySeq`
    
    ### What changes were proposed in this pull request?
    The `Literal.create` function supports `immuable.ArraySeq`, but the 
`Literal.apply` function does not. So this pr make the `Literal.apply` function 
to also support `immuable.ArraySeq`.
    
    ### Why are the changes needed?
    Make `Literal.apply` support `s.c.immuable.ArraySeq` as `Literal.create`
    
    ### Does this PR introduce _any_ user-facing change?
    Yes, user can create `Literal` using the `Literal.apply` function with 
`s.c.immuable.ArraySeq` as input.
    
    ### How was this patch tested?
    Add a new test
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No
    
    Closes #44607 from LuciferYang/SPARK-46604.
    
    Authored-by: yangjie01 <yangji...@baidu.com>
    Signed-off-by: Dongjoon Hyun <dh...@apple.com>
---
 .../org/apache/spark/sql/catalyst/expressions/literals.scala     | 3 ++-
 .../spark/sql/catalyst/expressions/LiteralExpressionSuite.scala  | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
index c406ba0707b3..79b2985adc1d 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
@@ -32,7 +32,7 @@ import java.time.{Duration, Instant, LocalDate, 
LocalDateTime, Period, ZoneOffse
 import java.util
 import java.util.Objects
 
-import scala.collection.mutable
+import scala.collection.{immutable, mutable}
 import scala.math.{BigDecimal, BigInt}
 import scala.reflect.runtime.universe.TypeTag
 import scala.util.Try
@@ -91,6 +91,7 @@ object Literal {
     case p: Period => Literal(periodToMonths(p), YearMonthIntervalType())
     case a: Array[Byte] => Literal(a, BinaryType)
     case a: mutable.ArraySeq[_] => apply(a.array)
+    case a: immutable.ArraySeq[_] => apply(a.unsafeArray)
     case a: Array[_] =>
       val elementType = componentTypeToDataType(a.getClass.getComponentType())
       val dataType = ArrayType(elementType)
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala
index 0a1acd06bd9e..f63b60f5ebba 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/LiteralExpressionSuite.scala
@@ -477,4 +477,13 @@ class LiteralExpressionSuite extends SparkFunSuite with 
ExpressionEvalHelper {
       Literal.create(UTF8String.fromString("Spark SQL"), 
ObjectType(classOf[UTF8String])),
       UTF8String.fromString("Spark SQL"))
   }
+
+  test("SPARK-46604: Literal support immutable ArraySeq") {
+    import org.apache.spark.util.ArrayImplicits._
+    val immArraySeq = Array(1.0, 4.0).toImmutableArraySeq
+    val expected = toCatalyst(immArraySeq)
+    checkEvaluation(Literal(immArraySeq), expected)
+    checkEvaluation(Literal.create(immArraySeq), expected)
+    checkEvaluation(Literal.create(immArraySeq, ArrayType(DoubleType)), 
expected)
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to