Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/4826#discussion_r25562103
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
---
@@ -592,13 +595,79 @@ class MetastoreDataSourcesSuite extends QueryTest
with BeforeAndAfterEach {
}
}
+ test("Pre insert nullability check (ArrayType)") {
+ val df1 =
+ createDataFrame(Tuple1(Seq(Int.box(1), null.asInstanceOf[Integer]))
:: Nil).toDF("a")
+ val expectedSchema1 =
+ StructType(
+ StructField("a", ArrayType(IntegerType, containsNull = true),
nullable = true) :: Nil)
+ assert(df1.schema === expectedSchema1)
+ df1.saveAsTable("arrayInParquet", "parquet", SaveMode.Overwrite)
+
+ val df2 =
+ createDataFrame(Tuple1(Seq(2, 3)) :: Nil).toDF("a")
+ val expectedSchema2 =
+ StructType(
+ StructField("a", ArrayType(IntegerType, containsNull = false),
nullable = true) :: Nil)
+ assert(df2.schema === expectedSchema2)
+ df2.insertInto("arrayInParquet", overwrite = false)
+ createDataFrame(Tuple1(Seq(4, 5)) :: Nil).toDF("a")
+ .saveAsTable("arrayInParquet", SaveMode.Append) // This one
internally calls df2.insertInto.
+ createDataFrame(Tuple1(Seq(Int.box(6), null.asInstanceOf[Integer])) ::
Nil).toDF("a")
+ .saveAsTable("arrayInParquet", "parquet", SaveMode.Append)
+ refreshTable("arrayInParquet")
+
+ checkAnswer(
+ sql("SELECT a FROM arrayInParquet"),
+ Row(ArrayBuffer(1, null)) ::
+ Row(ArrayBuffer(2, 3)) ::
+ Row(ArrayBuffer(4, 5)) ::
+ Row(ArrayBuffer(6, null)) :: Nil)
+
+ sql("DROP TABLE arrayInParquet")
+ }
+
+ test("Pre insert nullability check (MapType)") {
+ val df1 =
+ createDataFrame(Tuple1(Map(1 -> null.asInstanceOf[Integer])) ::
Nil).toDF("a")
+ val mapType1 = MapType(IntegerType, IntegerType, valueContainsNull =
true)
+ val expectedSchema1 =
+ StructType(
+ StructField("a", mapType1, nullable = true) :: Nil)
+ assert(df1.schema === expectedSchema1)
+ df1.saveAsTable("mapInParquet", "parquet", SaveMode.Overwrite)
+
+ val df2 =
+ createDataFrame(Tuple1(Map(2 -> 3)) :: Nil).toDF("a")
+ val mapType2 = MapType(IntegerType, IntegerType, valueContainsNull =
false)
+ val expectedSchema2 =
+ StructType(
+ StructField("a", mapType2, nullable = true) :: Nil)
+ assert(df2.schema === expectedSchema2)
+ df2.insertInto("mapInParquet", overwrite = false)
+ createDataFrame(Tuple1(Map(4 -> 5)) :: Nil).toDF("a")
+ .saveAsTable("mapInParquet", SaveMode.Append) // This one internally
calls df2.insertInto.
+ createDataFrame(Tuple1(Map(6 -> null.asInstanceOf[Integer])) ::
Nil).toDF("a")
+ .saveAsTable("mapInParquet", "parquet", SaveMode.Append)
+ refreshTable("mapInParquet")
+
+ checkAnswer(
+ sql("SELECT a FROM mapInParquet"),
+ Row(Map(1 -> null)) ::
+ Row(Map(2 -> 3)) ::
+ Row(Map(4 -> 5)) ::
+ Row(Map(6 -> null)) :: Nil)
+
+ sql("DROP TABLE mapInParquet")
+ }
+
test("SPARK-6024 wide schema support") {
// We will need 80 splits for this schema if the threshold is 4000.
val schema = StructType((1 to 5000).map(i => StructField(s"c_${i}",
StringType, true)))
assert(
schema.json.size > conf.schemaStringLengthThreshold,
"To correctly test the fix of SPARK-6024, the value of " +
- s"spark.sql.sources.schemaStringLengthThreshold needs to be less
than ${schema.json.size}")
+ s"spark.sql.sources.schemaStringLengthThreshold needs to be less
than ${schema.json.size}")
--- End diff --
looks like a spurious change.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]