From bb9fa037605b25c8503f288c3e6d870a4b208904 Mon Sep 17 00:00:00 2001 From: Maryann Xue Date: Tue, 19 Jun 2018 10:05:42 -0700 Subject: [PATCH] Simplify test case --- .../spark/sql/sources/InsertSuite.scala | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala index e130e03113b17..40f56d4b76564 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala @@ -46,21 +46,10 @@ case class SimpleInsert(userSpecifiedSchema: StructType)(@transient val sparkSes override def schema: StructType = userSpecifiedSchema override def insert(input: DataFrame, overwrite: Boolean): Unit = { - input.foreach { row => - schema.fields.zipWithIndex.filter(!_._1.nullable).foreach { field => - if (row.get(field._2) == null) { - throw new NotNullableViolationException(field._1.name) - } - } - } + input.collect } } -class NotNullableViolationException(val message: String) - extends Exception(message) with Serializable { - override def getMessage: String = s"Value for column '$message' cannot be null." -} - class InsertSuite extends DataSourceTest with SharedSQLContext { import testImplicits._ @@ -559,7 +548,7 @@ class InsertSuite extends DataSourceTest with SharedSQLContext { test("SPARK-24583 Wrong schema type in InsertIntoDataSourceCommand") { withTable("test_table") { val schema = new StructType() - .add("i", IntegerType, false) + .add("i", LongType, false) .add("s", StringType, false) val newTable = CatalogTable( identifier = TableIdentifier("test_table", None), @@ -576,27 +565,8 @@ class InsertSuite extends DataSourceTest with SharedSQLContext { spark.sessionState.catalog.createTable(newTable, false) - def verifyException(e: Exception, column: String): Unit = { - var ex = e.getCause - while (ex != null && - !ex.isInstanceOf[NotNullableViolationException]) { - ex = ex.getCause - } - if (ex == null) { - fail(s"Expected a NotNullableViolationException but got '${e.getMessage}'.") - } - assert(ex.getMessage.contains(s"Value for column '$column' cannot be null.")) - } - sql("INSERT INTO TABLE test_table SELECT 1, 'a'") - verifyException( - intercept[SparkException] { - sql("INSERT INTO TABLE test_table SELECT null, 'b'") - }, "i") - verifyException( - intercept[SparkException] { - sql("INSERT INTO TABLE test_table SELECT 2, null") - }, "s") + sql("INSERT INTO TABLE test_table SELECT 2, null") } } }