Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-45314 Drop Scala 2.12 and make Scala 2.13 by default
  3. SPARK-46124

Replace explicit `ArrayOps#toSeq` with `s.c.immutable.ArraySeq.unsafeWrapArray`

    XMLWordPrintableJSON

Details

    Description

      There is a behavioral difference between Scala 2.13 and 2.12 for explicit `ArrayOps.toSeq` calls, similar to the implicit conversion from `Array` to `Seq`.

      In Scala 2.12, it returns a `mutable.WrappedArray`, which does not involve a collection copy.

      ```scala
      Welcome to Scala 2.12.18 (OpenJDK 64-Bit Server VM, Java 17.0.9).
      Type in expressions for evaluation. Or try :help.

      scala> Array(1,2,3).toSeq
      res0: Seq[Int] = WrappedArray(1, 2, 3)
      ```

      However, in Scala 2.13, it returns an `immutable.ArraySeq` that with collection copy.

      Since we have always used the non-collection copy behavior for this explicit conversion in the era of Scala 2.12, it is safe to assume that no collection copy is needed for Scala 2.13.

      Attachments

        Activity

          People

            LuciferYang Yang Jie
            LuciferYang Yang Jie
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: