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-1757 Failing test for saving null primitives with .saveAsParquetFile() #690

Closed
wants to merge 3 commits into from
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 @@ -41,6 +41,9 @@ object ScalaReflection {

/** Returns a catalyst DataType for the given Scala Type using reflection. */
def schemaFor(tpe: `Type`): DataType = tpe match {
case t if t <:< typeOf[Option[_]] =>
val TypeRef(_, _, Seq(optType)) = t
schemaFor(optType)
case t if t <:< typeOf[Product] =>
val params = t.member("<init>": TermName).asMethod.paramss
StructType(
Expand All @@ -59,9 +62,6 @@ object ScalaReflection {
case t if t <:< typeOf[String] => StringType
case t if t <:< typeOf[Timestamp] => TimestampType
case t if t <:< typeOf[BigDecimal] => DecimalType
case t if t <:< typeOf[Option[_]] =>
val TypeRef(_, _, Seq(optType)) = t
schemaFor(optType)
case t if t <:< typeOf[java.lang.Integer] => IntegerType
case t if t <:< typeOf[java.lang.Long] => LongType
case t if t <:< typeOf[java.lang.Double] => DoubleType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ import org.apache.spark.sql.test.TestSQLContext._

case class TestRDDEntry(key: Int, value: String)

case class NullReflectData(
intField: java.lang.Integer,
longField: java.lang.Long,
floatField: java.lang.Float,
doubleField: java.lang.Double,
booleanField: java.lang.Boolean)

case class OptionalReflectData(
intField: Option[Int],
longField: Option[Long],
floatField: Option[Float],
doubleField: Option[Double],
booleanField: Option[Boolean])

class ParquetQuerySuite extends QueryTest with FunSuite with BeforeAndAfterAll {
import TestData._
TestData // Load test data tables.
Expand Down Expand Up @@ -195,5 +209,35 @@ class ParquetQuerySuite extends QueryTest with FunSuite with BeforeAndAfterAll {
Utils.deleteRecursively(ParquetTestData.testDir)
ParquetTestData.writeFile()
}

test("save and load case class RDD with nulls as parquet") {
val data = NullReflectData(null, null, null, null, null)
val rdd = sparkContext.parallelize(data :: Nil)

val file = getTempFilePath("parquet")
val path = file.toString
rdd.saveAsParquetFile(path)
val readFile = parquetFile(path)

val rdd_saved = readFile.collect()
assert(rdd_saved(0) === Seq.fill(5)(null))
Utils.deleteRecursively(file)
assert(true)
}

test("save and load case class RDD with Nones as parquet") {
val data = OptionalReflectData(null, null, null, null, null)
val rdd = sparkContext.parallelize(data :: Nil)

val file = getTempFilePath("parquet")
val path = file.toString
rdd.saveAsParquetFile(path)
val readFile = parquetFile(path)

val rdd_saved = readFile.collect()
assert(rdd_saved(0) === Seq.fill(5)(null))
Utils.deleteRecursively(file)
assert(true)
}
}