1717
1818package org .apache .spark .sql .connect .client .jdbc
1919
20- import java .sql .{ResultSet , SQLException , Types }
20+ import java .math .BigDecimal
21+ import java .nio .charset .StandardCharsets
22+ import java .sql .{Date , ResultSet , SQLException , Time , Timestamp , Types }
23+ import java .util .{Calendar , TimeZone }
2124
2225import scala .util .Using
2326
@@ -235,7 +238,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
235238 val decimalType = s " DECIMAL( $precision, $scale) "
236239 withExecuteQuery(s " SELECT cast(' $value' as $decimalType) " ) { rs =>
237240 assert(rs.next())
238- assert(rs.getBigDecimal(1 ) === new java.math. BigDecimal (value))
241+ assert(rs.getBigDecimal(1 ) === new BigDecimal (value))
239242 assert(! rs.wasNull)
240243 assert(! rs.next())
241244
@@ -295,14 +298,14 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
295298 (" cast(1 AS FLOAT)" , (rs : ResultSet ) => rs.getFloat(1 ), 1 .toFloat),
296299 (" cast(1 AS DOUBLE)" , (rs : ResultSet ) => rs.getDouble(1 ), 1 .toDouble),
297300 (" cast(1 AS DECIMAL(10,5))" , (rs : ResultSet ) => rs.getBigDecimal(1 ),
298- new java.math. BigDecimal (" 1.00000" )),
301+ new BigDecimal (" 1.00000" )),
299302 (" CAST(X'0A0B0C' AS BINARY)" , (rs : ResultSet ) => rs.getBytes(1 ),
300303 Array [Byte ](0x0A , 0x0B , 0x0C )),
301304 (" date '2023-11-15'" , (rs : ResultSet ) => rs.getDate(1 ),
302- java.sql. Date .valueOf(" 2023-11-15" )),
305+ Date .valueOf(" 2023-11-15" )),
303306 (" time '12:34:56.123456'" , (rs : ResultSet ) => rs.getTime(1 ), {
304307 val millis = timeToMillis(12 , 34 , 56 , 123 )
305- new java.sql. Time (millis)
308+ new Time (millis)
306309 })
307310 ).foreach {
308311 case (query, getter, expectedValue) =>
@@ -327,7 +330,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
327330 test(" get date type" ) {
328331 withExecuteQuery(" SELECT date '2023-11-15'" ) { rs =>
329332 assert(rs.next())
330- assert(rs.getDate(1 ) === java.sql. Date .valueOf(" 2023-11-15" ))
333+ assert(rs.getDate(1 ) === Date .valueOf(" 2023-11-15" ))
331334 assert(! rs.wasNull)
332335 assert(! rs.next())
333336
@@ -369,7 +372,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
369372 test(" get date type by column label" ) {
370373 withExecuteQuery(" SELECT date '2025-11-15' as test_date" ) { rs =>
371374 assert(rs.next())
372- assert(rs.getDate(" test_date" ) === java.sql. Date .valueOf(" 2025-11-15" ))
375+ assert(rs.getDate(" test_date" ) === Date .valueOf(" 2025-11-15" ))
373376 assert(! rs.wasNull)
374377 assert(! rs.next())
375378 }
@@ -387,7 +390,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
387390 assert(! rs.wasNull)
388391
389392 val stringValue = rs.getString(1 )
390- val expectedString = new String (testBytes, java.nio.charset. StandardCharsets .UTF_8 )
393+ val expectedString = new String (testBytes, StandardCharsets .UTF_8 )
391394 assert(stringValue === expectedString)
392395
393396 assert(! rs.next())
@@ -402,7 +405,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
402405 }
403406
404407 test(" get binary type with UTF-8 text" ) {
405- val textBytes = " \\ xDeAdBeEf" .getBytes(java.nio.charset. StandardCharsets .UTF_8 )
408+ val textBytes = " \\ xDeAdBeEf" .getBytes(StandardCharsets .UTF_8 )
406409 val hexString = textBytes.map(b => " %02X" .format(b)).mkString
407410 withExecuteQuery(s " SELECT CAST(X' $hexString' AS BINARY) " ) { rs =>
408411 assert(rs.next())
@@ -443,8 +446,8 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
443446 assert(bytes.sameElements(testBytes))
444447 assert(! rs.wasNull)
445448
446- val stringValue = rs.getString(1 )
447- val expectedString = new String (testBytes, java.nio.charset. StandardCharsets .UTF_8 )
449+ val stringValue = rs.getString(" test_binary " )
450+ val expectedString = new String (testBytes, StandardCharsets .UTF_8 )
448451 assert(stringValue === expectedString)
449452
450453 assert(! rs.next())
@@ -575,7 +578,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
575578 stmt.execute(s " set spark.sql.datetime.java8API.enabled= $java8APIEnabled" )
576579 Using .resource(stmt.executeQuery(" SELECT date '2025-11-15'" )) { rs =>
577580 assert(rs.next())
578- assert(rs.getDate(1 ) === java.sql. Date .valueOf(" 2025-11-15" ))
581+ assert(rs.getDate(1 ) === Date .valueOf(" 2025-11-15" ))
579582 assert(! rs.wasNull)
580583 assert(! rs.next())
581584 }
@@ -604,7 +607,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
604607 assert(rs.next())
605608 val timestamp = rs.getTimestamp(1 )
606609 assert(timestamp !== null )
607- assert(timestamp === java.sql. Timestamp .valueOf(" 2025-11-15 10:30:45.123456" ))
610+ assert(timestamp === Timestamp .valueOf(" 2025-11-15 10:30:45.123456" ))
608611 assert(! rs.wasNull)
609612 assert(! rs.next())
610613
@@ -650,18 +653,18 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
650653 // Test by column label
651654 val timestamp = rs.getTimestamp(" test_timestamp" )
652655 assert(timestamp !== null )
653- assert(timestamp === java.sql. Timestamp .valueOf(" 2025-11-15 10:30:45.987654" ))
656+ assert(timestamp === Timestamp .valueOf(" 2025-11-15 10:30:45.987654" ))
654657 assert(! rs.wasNull)
655658
656659 // Test with calendar - should return same value (Calendar is ignored)
657660 // Note: Spark Connect handles timezone at server, Calendar param is for API compliance
658- val calUTC = java.util. Calendar .getInstance(java.util. TimeZone .getTimeZone(" UTC" ))
661+ val calUTC = Calendar .getInstance(TimeZone .getTimeZone(" UTC" ))
659662 val timestampUTC = rs.getTimestamp(1 , calUTC)
660663 assert(timestampUTC !== null )
661664 assert(timestampUTC.getTime === timestamp.getTime)
662665
663- val calPST = java.util. Calendar .getInstance(
664- java.util. TimeZone .getTimeZone(" America/Los_Angeles" ))
666+ val calPST = Calendar .getInstance(
667+ TimeZone .getTimeZone(" America/Los_Angeles" ))
665668 val timestampPST = rs.getTimestamp(1 , calPST)
666669 assert(timestampPST !== null )
667670 // Same value regardless of calendar
@@ -687,7 +690,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
687690 assert(rs.next())
688691
689692 // Calendar parameter should not affect null handling
690- val cal = java.util. Calendar .getInstance(java.util. TimeZone .getTimeZone(" UTC" ))
693+ val cal = Calendar .getInstance(TimeZone .getTimeZone(" UTC" ))
691694 val timestamp = rs.getTimestamp(1 , cal)
692695 assert(timestamp === null )
693696 assert(rs.wasNull)
@@ -700,7 +703,7 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
700703 assert(rs.next())
701704 val timestamp = rs.getTimestamp(1 )
702705 assert(timestamp !== null )
703- assert(timestamp === java.sql. Timestamp .valueOf(" 2025-11-15 10:30:45.123456" ))
706+ assert(timestamp === Timestamp .valueOf(" 2025-11-15 10:30:45.123456" ))
704707 assert(! rs.wasNull)
705708 assert(! rs.next())
706709
@@ -726,11 +729,11 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
726729 // Test by column label
727730 val timestamp = rs.getTimestamp(" test_ts_ntz" )
728731 assert(timestamp !== null )
729- assert(timestamp === java.sql. Timestamp .valueOf(" 2025-11-15 14:22:33.789456" ))
732+ assert(timestamp === Timestamp .valueOf(" 2025-11-15 14:22:33.789456" ))
730733 assert(! rs.wasNull)
731734
732735 // Test with calendar - should return same value (Calendar is ignored)
733- val calUTC = java.util. Calendar .getInstance(java.util. TimeZone .getTimeZone(" UTC" ))
736+ val calUTC = Calendar .getInstance(TimeZone .getTimeZone(" UTC" ))
734737 val timestampCal = rs.getTimestamp(1 , calUTC)
735738 assert(timestampCal !== null )
736739 assert(timestampCal.getTime === timestamp.getTime)
@@ -762,13 +765,13 @@ class SparkConnectJdbcDataTypeSuite extends ConnectFunSuite with RemoteSparkSess
762765 // Test TIMESTAMP type
763766 val timestamp = rs.getTimestamp(1 )
764767 assert(timestamp !== null )
765- assert(timestamp === java.sql. Timestamp .valueOf(" 2025-11-15 10:30:45.123456" ))
768+ assert(timestamp === Timestamp .valueOf(" 2025-11-15 10:30:45.123456" ))
766769 assert(! rs.wasNull)
767770
768771 // Test TIMESTAMP_NTZ type
769772 val timestampNtz = rs.getTimestamp(2 )
770773 assert(timestampNtz !== null )
771- assert(timestampNtz === java.sql. Timestamp .valueOf(" 2025-11-15 14:22:33.789012" ))
774+ assert(timestampNtz === Timestamp .valueOf(" 2025-11-15 14:22:33.789012" ))
772775 assert(! rs.wasNull)
773776
774777 assert(! rs.next())
0 commit comments