aboutsummaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorsureshthalamati <suresh.thalamati@gmail.com>2017-02-14 15:34:12 -0800
committerWenchen Fan <wenchen@databricks.com>2017-02-14 15:34:12 -0800
commitf48c5a57d6488d5598534ca5834e008504f464fe (patch)
tree3a27c7bbc6a8401aa2a3a0e8dfcc3ad7b203f811 /external
parentda7aef7a0ea921a2d8ee37b0e3939245e4168355 (diff)
downloadspark-f48c5a57d6488d5598534ca5834e008504f464fe.tar.gz
spark-f48c5a57d6488d5598534ca5834e008504f464fe.tar.bz2
spark-f48c5a57d6488d5598534ca5834e008504f464fe.zip
[SPARK-19318][SQL] Fix to treat JDBC connection properties specified by the user in case-sensitive manner.
## What changes were proposed in this pull request? The reason for test failure is that the property “oracle.jdbc.mapDateToTimestamp” set by the test was getting converted into all lower case. Oracle database expects this property in case-sensitive manner. This test was passing in previous releases because connection properties were sent as user specified for the test case scenario. Fixes to handle all option uniformly in case-insensitive manner, converted the JDBC connection properties also to lower case. This PR enhances CaseInsensitiveMap to keep track of input case-sensitive keys , and uses those when creating connection properties that are passed to the JDBC connection. Alternative approach PR https://github.com/apache/spark/pull/16847 is to pass original input keys to JDBC data source by adding check in the Data source class and handle case-insensitivity in the JDBC source code. ## How was this patch tested? Added new test cases to JdbcSuite , and OracleIntegrationSuite. Ran docker integration tests passed on my laptop, all tests passed successfully. Author: sureshthalamati <suresh.thalamati@gmail.com> Closes #16891 from sureshthalamati/jdbc_case_senstivity_props_fix-SPARK-19318.
Diffstat (limited to 'external')
-rw-r--r--external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/OracleIntegrationSuite.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/OracleIntegrationSuite.scala b/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/OracleIntegrationSuite.scala
index 8c880f3ee5..1bb89a361c 100644
--- a/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/OracleIntegrationSuite.scala
+++ b/external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/OracleIntegrationSuite.scala
@@ -62,6 +62,31 @@ class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSQLCo
}
override def dataPreparation(conn: Connection): Unit = {
+ conn.prepareStatement("CREATE TABLE datetime (id NUMBER(10), d DATE, t TIMESTAMP)")
+ .executeUpdate()
+ conn.prepareStatement(
+ """INSERT INTO datetime VALUES
+ |(1, {d '1991-11-09'}, {ts '1996-01-01 01:23:45'})
+ """.stripMargin.replaceAll("\n", " ")).executeUpdate()
+ conn.commit()
+
+ sql(
+ s"""
+ |CREATE TEMPORARY VIEW datetime
+ |USING org.apache.spark.sql.jdbc
+ |OPTIONS (url '$jdbcUrl', dbTable 'datetime', oracle.jdbc.mapDateToTimestamp 'false')
+ """.stripMargin.replaceAll("\n", " "))
+
+ conn.prepareStatement("CREATE TABLE datetime1 (id NUMBER(10), d DATE, t TIMESTAMP)")
+ .executeUpdate()
+ conn.commit()
+
+ sql(
+ s"""
+ |CREATE TEMPORARY VIEW datetime1
+ |USING org.apache.spark.sql.jdbc
+ |OPTIONS (url '$jdbcUrl', dbTable 'datetime1', oracle.jdbc.mapDateToTimestamp 'false')
+ """.stripMargin.replaceAll("\n", " "))
}
test("SPARK-12941: String datatypes to be mapped to Varchar in Oracle") {
@@ -149,4 +174,15 @@ class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSQLCo
assert(values.getDate(9).equals(dateVal))
assert(values.getTimestamp(10).equals(timestampVal))
}
+
+ test("SPARK-19318: connection property keys should be case-sensitive") {
+ def checkRow(row: Row): Unit = {
+ assert(row.getInt(0) == 1)
+ assert(row.getDate(1).equals(Date.valueOf("1991-11-09")))
+ assert(row.getTimestamp(2).equals(Timestamp.valueOf("1996-01-01 01:23:45")))
+ }
+ checkRow(sql("SELECT * FROM datetime where id = 1").head())
+ sql("INSERT INTO TABLE datetime1 SELECT * FROM datetime where id = 1")
+ checkRow(sql("SELECT * FROM datetime1 where id = 1").head())
+ }
}