@@ -24,7 +24,6 @@ import java.util.{Calendar, GregorianCalendar, Properties, TimeZone}
24
24
25
25
import scala .collection .JavaConverters ._
26
26
27
- import org .h2 .jdbc .JdbcSQLException
28
27
import org .mockito .ArgumentMatchers ._
29
28
import org .mockito .Mockito ._
30
29
import org .scalatest .{BeforeAndAfter , PrivateMethodTester }
@@ -54,7 +53,8 @@ class JDBCSuite extends QueryTest
54
53
val urlWithUserAndPass = " jdbc:h2:mem:testdb0;user=testUser;password=testPass"
55
54
var conn : java.sql.Connection = null
56
55
57
- val testBytes = Array [Byte ](99 .toByte, 134 .toByte, 135 .toByte, 200 .toByte, 205 .toByte)
56
+ val testBytes = Array [Byte ](99 .toByte, 134 .toByte, 135 .toByte, 200 .toByte, 205 .toByte) ++
57
+ Array .fill(15 )(0 .toByte)
58
58
59
59
val testH2Dialect = new JdbcDialect {
60
60
override def canHandle (url : String ): Boolean = url.startsWith(" jdbc:h2" )
@@ -87,7 +87,6 @@ class JDBCSuite extends QueryTest
87
87
val properties = new Properties ()
88
88
properties.setProperty(" user" , " testUser" )
89
89
properties.setProperty(" password" , " testPass" )
90
- properties.setProperty(" rowId" , " false" )
91
90
92
91
conn = DriverManager .getConnection(url, properties)
93
92
conn.prepareStatement(" create schema test" ).executeUpdate()
@@ -162,7 +161,7 @@ class JDBCSuite extends QueryTest
162
161
|OPTIONS (url ' $url', dbtable 'TEST.STRTYPES', user 'testUser', password 'testPass')
163
162
""" .stripMargin.replaceAll(" \n " , " " ))
164
163
165
- conn.prepareStatement(" create table test.timetypes (a TIME, b DATE, c TIMESTAMP)"
164
+ conn.prepareStatement(" create table test.timetypes (a TIME, b DATE, c TIMESTAMP(7) )"
166
165
).executeUpdate()
167
166
conn.prepareStatement(" insert into test.timetypes values ('12:34:56', "
168
167
+ " '1996-01-01', '2002-02-20 11:22:33.543543543')" ).executeUpdate()
@@ -177,12 +176,12 @@ class JDBCSuite extends QueryTest
177
176
""" .stripMargin.replaceAll(" \n " , " " ))
178
177
179
178
conn.prepareStatement(" CREATE TABLE test.timezone (tz TIMESTAMP WITH TIME ZONE) " +
180
- " AS SELECT '1999-01-08 04:05:06.543543543 GMT -08:00'" )
179
+ " AS SELECT '1999-01-08 04:05:06.543543543-08:00'" )
181
180
.executeUpdate()
182
181
conn.commit()
183
182
184
- conn.prepareStatement(" CREATE TABLE test.array (ar ARRAY) " +
185
- " AS SELECT '( 1, 2, 3)' " )
183
+ conn.prepareStatement(" CREATE TABLE test.array_table (ar Integer ARRAY) " +
184
+ " AS SELECT ARRAY[ 1, 2, 3] " )
186
185
.executeUpdate()
187
186
conn.commit()
188
187
@@ -638,7 +637,7 @@ class JDBCSuite extends QueryTest
638
637
assert(rows(0 ).getAs[Array [Byte ]](0 ).sameElements(testBytes))
639
638
assert(rows(0 ).getString(1 ).equals(" Sensitive" ))
640
639
assert(rows(0 ).getString(2 ).equals(" Insensitive" ))
641
- assert(rows(0 ).getString(3 ).equals(" Twenty-byte CHAR" ))
640
+ assert(rows(0 ).getString(3 ).equals(" Twenty-byte CHAR " ))
642
641
assert(rows(0 ).getAs[Array [Byte ]](4 ).sameElements(testBytes))
643
642
assert(rows(0 ).getString(5 ).equals(" I am a clob!" ))
644
643
}
@@ -729,20 +728,6 @@ class JDBCSuite extends QueryTest
729
728
assert(math.abs(rows(0 ).getDouble(1 ) - 1.00000023841859331 ) < 1e-12 )
730
729
}
731
730
732
- test(" Pass extra properties via OPTIONS" ) {
733
- // We set rowId to false during setup, which means that _ROWID_ column should be absent from
734
- // all tables. If rowId is true (default), the query below doesn't throw an exception.
735
- intercept[JdbcSQLException ] {
736
- sql(
737
- s """
738
- |CREATE OR REPLACE TEMPORARY VIEW abc
739
- |USING org.apache.spark.sql.jdbc
740
- |OPTIONS (url ' $url', dbtable '(SELECT _ROWID_ FROM test.people)',
741
- | user 'testUser', password 'testPass')
742
- """ .stripMargin.replaceAll(" \n " , " " ))
743
- }
744
- }
745
-
746
731
test(" Remap types via JdbcDialects" ) {
747
732
JdbcDialects .registerDialect(testH2Dialect)
748
733
val df = spark.read.jdbc(urlWithUserAndPass, " TEST.PEOPLE" , new Properties ())
@@ -1375,7 +1360,7 @@ class JDBCSuite extends QueryTest
1375
1360
}.getMessage
1376
1361
assert(e.contains(" Unsupported type TIMESTAMP_WITH_TIMEZONE" ))
1377
1362
e = intercept[SQLException ] {
1378
- spark.read.jdbc(urlWithUserAndPass, " TEST.ARRAY " , new Properties ()).collect()
1363
+ spark.read.jdbc(urlWithUserAndPass, " TEST.ARRAY_TABLE " , new Properties ()).collect()
1379
1364
}.getMessage
1380
1365
assert(e.contains(" Unsupported type ARRAY" ))
1381
1366
}
0 commit comments