Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-3447][SQL] Remove explicit conversion with JListWrapper to avoid NPE #2323

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -460,7 +460,6 @@ class SQLContext(@transient val sparkContext: SparkContext)
rdd: RDD[Array[Any]],
schema: StructType): SchemaRDD = {
import scala.collection.JavaConversions._
import scala.collection.convert.Wrappers.{JListWrapper, JMapWrapper}

def needsConversion(dataType: DataType): Boolean = dataType match {
case ByteType => true
Expand All @@ -482,8 +481,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
case (null, _) => null

case (c: java.util.List[_], ArrayType(elementType, _)) =>
val converted = c.map { e => convert(e, elementType)}
JListWrapper(converted)
c.map { e => convert(e, elementType)}: Seq[Any]

case (c, ArrayType(elementType, _)) if c.getClass.isArray =>
c.asInstanceOf[Array[_]].map(e => convert(e, elementType)): Seq[Any]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
package org.apache.spark.sql.json

import scala.collection.Map
import scala.collection.convert.Wrappers.{JMapWrapper, JListWrapper}
import scala.collection.JavaConversions._
import scala.collection.convert.Wrappers.JMapWrapper
import scala.math.BigDecimal

import com.fasterxml.jackson.databind.ObjectMapper
Expand Down Expand Up @@ -253,7 +254,7 @@ private[sql] object JsonRDD extends Logging {
// This issue is documented at https://issues.scala-lang.org/browse/SI-7005
JMapWrapper(map).mapValues(scalafy).map(identity)
case list: java.util.List[_] =>
JListWrapper(list).map(scalafy)
(list: Seq[_]).map(scalafy)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, after checking the code again, I think .map(scalafy) will convert the JListWrapper at here to an ArrayBuffer (JListWrapper is a Buffer and Buffer's newBuilder returns ArrayBuffer) and we will not have the Kryo issue. I tried from pyspark.sql import SQLContext;SQLContext(sc).jsonRDD(sc.parallelize(['{"a":[3]}']))._jschema_rdd.collect() and it's fine.

case atom => atom
}

Expand Down