diff options
Diffstat (limited to 'sql/core/src/test')
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCWriteSuite.scala | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCWriteSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCWriteSuite.scala index f49ac23149..354af29d42 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCWriteSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCWriteSuite.scala @@ -24,9 +24,9 @@ import scala.collection.JavaConverters.propertiesAsScalaMapConverter import org.scalatest.BeforeAndAfter -import org.apache.spark.SparkException -import org.apache.spark.sql.{Row, SaveMode} +import org.apache.spark.sql.{AnalysisException, Row, SaveMode} import org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions +import org.apache.spark.sql.internal.SQLConf import org.apache.spark.sql.test.SharedSQLContext import org.apache.spark.sql.types._ import org.apache.spark.util.Utils @@ -96,6 +96,10 @@ class JDBCWriteSuite extends SharedSQLContext with BeforeAndAfter { StructField("id", IntegerType) :: StructField("seq", IntegerType) :: Nil) + private lazy val schema4 = StructType( + StructField("NAME", StringType) :: + StructField("ID", IntegerType) :: Nil) + test("Basic CREATE") { val df = spark.createDataFrame(sparkContext.parallelize(arr2x2), schema2) @@ -165,6 +169,26 @@ class JDBCWriteSuite extends SharedSQLContext with BeforeAndAfter { assert(2 === spark.read.jdbc(url, "TEST.APPENDTEST", new Properties()).collect()(0).length) } + test("SPARK-18123 Append with column names with different cases") { + val df = spark.createDataFrame(sparkContext.parallelize(arr2x2), schema2) + val df2 = spark.createDataFrame(sparkContext.parallelize(arr1x2), schema4) + + df.write.jdbc(url, "TEST.APPENDTEST", new Properties()) + + withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") { + val m = intercept[AnalysisException] { + df2.write.mode(SaveMode.Append).jdbc(url, "TEST.APPENDTEST", new Properties()) + }.getMessage + assert(m.contains("Column \"NAME\" not found")) + } + + withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") { + df2.write.mode(SaveMode.Append).jdbc(url, "TEST.APPENDTEST", new Properties()) + assert(3 === spark.read.jdbc(url, "TEST.APPENDTEST", new Properties()).count()) + assert(2 === spark.read.jdbc(url, "TEST.APPENDTEST", new Properties()).collect()(0).length) + } + } + test("Truncate") { JdbcDialects.registerDialect(testH2Dialect) val df = spark.createDataFrame(sparkContext.parallelize(arr2x2), schema2) @@ -177,7 +201,7 @@ class JDBCWriteSuite extends SharedSQLContext with BeforeAndAfter { assert(1 === spark.read.jdbc(url1, "TEST.TRUNCATETEST", properties).count()) assert(2 === spark.read.jdbc(url1, "TEST.TRUNCATETEST", properties).collect()(0).length) - val m = intercept[SparkException] { + val m = intercept[AnalysisException] { df3.write.mode(SaveMode.Overwrite).option("truncate", true) .jdbc(url1, "TEST.TRUNCATETEST", properties) }.getMessage @@ -203,9 +227,10 @@ class JDBCWriteSuite extends SharedSQLContext with BeforeAndAfter { val df2 = spark.createDataFrame(sparkContext.parallelize(arr2x3), schema3) df.write.jdbc(url, "TEST.INCOMPATIBLETEST", new Properties()) - intercept[org.apache.spark.SparkException] { + val m = intercept[AnalysisException] { df2.write.mode(SaveMode.Append).jdbc(url, "TEST.INCOMPATIBLETEST", new Properties()) - } + }.getMessage + assert(m.contains("Column \"seq\" not found")) } test("INSERT to JDBC Datasource") { |