Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even without this PR, the following two lines can pass the test successfully. These two lines are just to increase test coverage.

checkEvaluation(Literal.create(immArraySeq), expected)
checkEvaluation(Literal.create(immArraySeq, ArrayType(DoubleType)), expected)

}
}