@@ -19,7 +19,7 @@ package org.apache.spark.sql.hive.thriftserver
19
19
20
20
import java .io .File
21
21
import java .net .ServerSocket
22
- import java .sql .{DriverManager , Statement }
22
+ import java .sql .{Date , DriverManager , Statement }
23
23
import java .util .concurrent .TimeoutException
24
24
25
25
import scala .collection .mutable .ArrayBuffer
@@ -51,6 +51,15 @@ import org.apache.spark.sql.hive.HiveShim
51
51
class HiveThriftServer2Suite extends FunSuite with Logging {
52
52
Class .forName(classOf [HiveDriver ].getCanonicalName)
53
53
54
+ object TestData {
55
+ def getTestDataFilePath (name : String ) = {
56
+ Thread .currentThread().getContextClassLoader.getResource(s " data/files/ $name" )
57
+ }
58
+
59
+ val smallKv = getTestDataFilePath(" small_kv.txt" )
60
+ val smallKvWithNull = getTestDataFilePath(" small_kv_with_null.txt" )
61
+ }
62
+
54
63
def randomListeningPort = {
55
64
// Let the system to choose a random available port to avoid collision with other parallel
56
65
// builds.
@@ -145,12 +154,8 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
145
154
}
146
155
}
147
156
148
- val env = Seq (
149
- // Resets SPARK_TESTING to avoid loading Log4J configurations in testing class paths
150
- " SPARK_TESTING" -> " 0" ,
151
- // Prevents loading classes out of the assembly jar. Otherwise Utils.sparkVersion can't read
152
- // proper version information from the jar manifest.
153
- " SPARK_PREPEND_CLASSES" -> " " )
157
+ // Resets SPARK_TESTING to avoid loading Log4J configurations in testing class paths
158
+ val env = Seq (" SPARK_TESTING" -> " 0" )
154
159
155
160
Process (command, None , env : _* ).run(ProcessLogger (
156
161
captureThriftServerOutput(" stdout" ),
@@ -194,13 +199,10 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
194
199
195
200
test(" Test JDBC query execution" ) {
196
201
withJdbcStatement() { statement =>
197
- val dataFilePath =
198
- Thread .currentThread().getContextClassLoader.getResource(" data/files/small_kv.txt" )
199
-
200
202
val queries =
201
203
s """ SET spark.sql.shuffle.partitions=3;
202
204
|CREATE TABLE test(key INT, val STRING);
203
- |LOAD DATA LOCAL INPATH ' $dataFilePath ' OVERWRITE INTO TABLE test;
205
+ |LOAD DATA LOCAL INPATH ' ${ TestData .smallKv} ' OVERWRITE INTO TABLE test;
204
206
|CACHE TABLE test;
205
207
""" .stripMargin.split(" ;" ).map(_.trim).filter(_.nonEmpty)
206
208
@@ -216,14 +218,10 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
216
218
217
219
test(" SPARK-3004 regression: result set containing NULL" ) {
218
220
withJdbcStatement() { statement =>
219
- val dataFilePath =
220
- Thread .currentThread().getContextClassLoader.getResource(
221
- " data/files/small_kv_with_null.txt" )
222
-
223
221
val queries = Seq (
224
222
" DROP TABLE IF EXISTS test_null" ,
225
223
" CREATE TABLE test_null(key INT, val STRING)" ,
226
- s " LOAD DATA LOCAL INPATH ' $dataFilePath ' OVERWRITE INTO TABLE test_null " )
224
+ s " LOAD DATA LOCAL INPATH ' ${ TestData .smallKvWithNull} ' OVERWRITE INTO TABLE test_null " )
227
225
228
226
queries.foreach(statement.execute)
229
227
@@ -270,24 +268,40 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
270
268
271
269
test(" SPARK-4292 regression: result set iterator issue" ) {
272
270
withJdbcStatement() { statement =>
273
- val dataFilePath =
274
- Thread .currentThread().getContextClassLoader.getResource(" data/files/small_kv.txt" )
275
-
276
271
val queries = Seq (
277
272
" DROP TABLE IF EXISTS test_4292" ,
278
273
" CREATE TABLE test_4292(key INT, val STRING)" ,
279
- s " LOAD DATA LOCAL INPATH ' $dataFilePath ' OVERWRITE INTO TABLE test_4292 " )
274
+ s " LOAD DATA LOCAL INPATH ' ${ TestData .smallKv} ' OVERWRITE INTO TABLE test_4292 " )
280
275
281
276
queries.foreach(statement.execute)
282
277
283
278
val resultSet = statement.executeQuery(" SELECT key FROM test_4292" )
284
279
285
280
Seq (238 , 86 , 311 , 27 , 165 ).foreach { key =>
286
281
resultSet.next()
287
- assert(resultSet.getInt(1 ) == key)
282
+ assert(resultSet.getInt(1 ) === key)
288
283
}
289
284
290
285
statement.executeQuery(" DROP TABLE IF EXISTS test_4292" )
291
286
}
292
287
}
288
+
289
+ test(" SPARK-4309 regression: Date type support" ) {
290
+ withJdbcStatement() { statement =>
291
+ val queries = Seq (
292
+ " DROP TABLE IF EXISTS test_date" ,
293
+ " CREATE TABLE test_date(key INT, value STRING)" ,
294
+ s " LOAD DATA LOCAL INPATH ' ${TestData .smallKv}' OVERWRITE INTO TABLE test_date " )
295
+
296
+ queries.foreach(statement.execute)
297
+
298
+ val resultSet = statement.executeQuery(
299
+ " SELECT CAST('2011-01-01' as date) FROM test_date LIMIT 1" )
300
+
301
+ assertResult(Date .valueOf(" 2011-01-01" )) {
302
+ resultSet.next()
303
+ resultSet.getDate(1 )
304
+ }
305
+ }
306
+ }
293
307
}
0 commit comments