Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19939#discussion_r156001560
--- Diff:
external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/OracleIntegrationSuite.scala
---
@@ -235,6 +239,61 @@ class OracleIntegrationSuite extends
DockerJDBCIntegrationSuite with SharedSQLCo
assert(types(1).equals("class java.sql.Timestamp"))
}
+ test("Column type TIMESTAMP with SESSION_LOCAL_TIMEZONE is different
from default") {
+ val defaultJVMTimeZone = TimeZone.getDefault
+ // Pick the timezone different from the current default time zone of
JVM
+ val sofiaTimeZone = TimeZone.getTimeZone("Europe/Sofia")
+ val shanghaiTimeZone = TimeZone.getTimeZone("Asia/Shanghai")
+ val localSessionTimeZone =
+ if (defaultJVMTimeZone == shanghaiTimeZone) sofiaTimeZone else
shanghaiTimeZone
+
+ withSQLConf(SQLConf.SESSION_LOCAL_TIMEZONE.key ->
localSessionTimeZone.getID) {
+ val e = intercept[java.sql.SQLException] {
+ val dfRead = sqlContext.read.jdbc(jdbcUrl, "ts_with_timezone", new
Properties)
+ dfRead.collect()
+ }.getMessage
+ assert(e.contains("Unrecognized SQL type -101"))
+ }
+ }
+
+ /**
+ * Change the Time Zone `timeZoneId` of JVM before executing `f`, then
switches back to the
+ * original after `f` returns.
+ * @param timeZoneId the ID for a TimeZone, either an abbreviation such
as "PST", a full name such
+ * as "America/Los_Angeles", or a custom ID such as
"GMT-8:00".
+ */
+ private def withTimeZone(timeZoneId: String)(f: => Unit): Unit = {
+ val originalLocale = TimeZone.getDefault
+ try {
+ // Add Locale setting
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId))
+ f
+ } finally {
+ TimeZone.setDefault(originalLocale)
+ }
+ }
+
+ test("Column TIMESTAMP with TIME ZONE(JVM timezone)") {
+ def checkRow(row: Row, ts: String): Unit = {
+ assert(row.getTimestamp(1).equals(Timestamp.valueOf(ts)))
+ }
+
+ val dfRead = sqlContext.read.jdbc(jdbcUrl, "ts_with_timezone", new
Properties)
+ withTimeZone("PST") {
--- End diff --
how do you make sure sesson time zone is same with JVM time zone?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]