@@ -19,9 +19,10 @@ 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
+ import scala .collection .JavaConversions ._
25
26
import scala .collection .mutable .ArrayBuffer
26
27
import scala .concurrent .duration ._
27
28
import scala .concurrent .{Await , Promise }
@@ -51,6 +52,15 @@ import org.apache.spark.sql.hive.HiveShim
51
52
class HiveThriftServer2Suite extends FunSuite with Logging {
52
53
Class .forName(classOf [HiveDriver ].getCanonicalName)
53
54
55
+ object TestData {
56
+ def getTestDataFilePath (name : String ) = {
57
+ Thread .currentThread().getContextClassLoader.getResource(s " data/files/ $name" )
58
+ }
59
+
60
+ val smallKv = getTestDataFilePath(" small_kv.txt" )
61
+ val smallKvWithNull = getTestDataFilePath(" small_kv_with_null.txt" )
62
+ }
63
+
54
64
def randomListeningPort = {
55
65
// Let the system to choose a random available port to avoid collision with other parallel
56
66
// builds.
@@ -145,12 +155,8 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
145
155
}
146
156
}
147
157
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" -> " " )
158
+ // Resets SPARK_TESTING to avoid loading Log4J configurations in testing class paths
159
+ val env = Seq (" SPARK_TESTING" -> " 0" )
154
160
155
161
Process (command, None , env : _* ).run(ProcessLogger (
156
162
captureThriftServerOutput(" stdout" ),
@@ -194,15 +200,12 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
194
200
195
201
test(" Test JDBC query execution" ) {
196
202
withJdbcStatement() { statement =>
197
- val dataFilePath =
198
- Thread .currentThread().getContextClassLoader.getResource(" data/files/small_kv.txt" )
199
-
200
- val queries =
201
- s """ SET spark.sql.shuffle.partitions=3;
202
- |CREATE TABLE test(key INT, val STRING);
203
- |LOAD DATA LOCAL INPATH ' $dataFilePath' OVERWRITE INTO TABLE test;
204
- |CACHE TABLE test;
205
- """ .stripMargin.split(" ;" ).map(_.trim).filter(_.nonEmpty)
203
+ val queries = Seq (
204
+ " SET spark.sql.shuffle.partitions=3" ,
205
+ " DROP TABLE IF EXISTS test" ,
206
+ " CREATE TABLE test(key INT, val STRING)" ,
207
+ s " LOAD DATA LOCAL INPATH ' ${TestData .smallKv}' OVERWRITE INTO TABLE test " ,
208
+ " CACHE TABLE test" )
206
209
207
210
queries.foreach(statement.execute)
208
211
@@ -216,14 +219,10 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
216
219
217
220
test(" SPARK-3004 regression: result set containing NULL" ) {
218
221
withJdbcStatement() { statement =>
219
- val dataFilePath =
220
- Thread .currentThread().getContextClassLoader.getResource(
221
- " data/files/small_kv_with_null.txt" )
222
-
223
222
val queries = Seq (
224
223
" DROP TABLE IF EXISTS test_null" ,
225
224
" CREATE TABLE test_null(key INT, val STRING)" ,
226
- s " LOAD DATA LOCAL INPATH ' $dataFilePath ' OVERWRITE INTO TABLE test_null " )
225
+ s " LOAD DATA LOCAL INPATH ' ${ TestData .smallKvWithNull} ' OVERWRITE INTO TABLE test_null " )
227
226
228
227
queries.foreach(statement.execute)
229
228
@@ -270,24 +269,63 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
270
269
271
270
test(" SPARK-4292 regression: result set iterator issue" ) {
272
271
withJdbcStatement() { statement =>
273
- val dataFilePath =
274
- Thread .currentThread().getContextClassLoader.getResource(" data/files/small_kv.txt" )
275
-
276
272
val queries = Seq (
277
273
" DROP TABLE IF EXISTS test_4292" ,
278
274
" CREATE TABLE test_4292(key INT, val STRING)" ,
279
- s " LOAD DATA LOCAL INPATH ' $dataFilePath ' OVERWRITE INTO TABLE test_4292 " )
275
+ s " LOAD DATA LOCAL INPATH ' ${ TestData .smallKv} ' OVERWRITE INTO TABLE test_4292 " )
280
276
281
277
queries.foreach(statement.execute)
282
278
283
279
val resultSet = statement.executeQuery(" SELECT key FROM test_4292" )
284
280
285
281
Seq (238 , 86 , 311 , 27 , 165 ).foreach { key =>
286
282
resultSet.next()
287
- assert(resultSet.getInt(1 ) == key)
283
+ assert(resultSet.getInt(1 ) === key)
288
284
}
289
285
290
286
statement.executeQuery(" DROP TABLE IF EXISTS test_4292" )
291
287
}
292
288
}
289
+
290
+ test(" SPARK-4309 regression: Date type support" ) {
291
+ withJdbcStatement() { statement =>
292
+ val queries = Seq (
293
+ " DROP TABLE IF EXISTS test_date" ,
294
+ " CREATE TABLE test_date(key INT, value STRING)" ,
295
+ s " LOAD DATA LOCAL INPATH ' ${TestData .smallKv}' OVERWRITE INTO TABLE test_date " )
296
+
297
+ queries.foreach(statement.execute)
298
+
299
+ assertResult(Date .valueOf(" 2011-01-01" )) {
300
+ val resultSet = statement.executeQuery(
301
+ " SELECT CAST('2011-01-01' as date) FROM test_date LIMIT 1" )
302
+ resultSet.next()
303
+ resultSet.getDate(1 )
304
+ }
305
+ }
306
+ }
307
+
308
+ test(" SPARK-4407 regression: Complex type support" ) {
309
+ withJdbcStatement() { statement =>
310
+ val queries = Seq (
311
+ " DROP TABLE IF EXISTS test_map" ,
312
+ " CREATE TABLE test_map(key INT, value STRING)" ,
313
+ s " LOAD DATA LOCAL INPATH ' ${TestData .smallKv}' OVERWRITE INTO TABLE test_map " )
314
+
315
+ queries.foreach(statement.execute)
316
+
317
+ assertResult(""" {238:"val_238"}""" ) {
318
+ val resultSet = statement.executeQuery(" SELECT MAP(key, value) FROM test_map LIMIT 1" )
319
+ resultSet.next()
320
+ resultSet.getString(1 )
321
+ }
322
+
323
+ assertResult(""" ["238","val_238"]""" ) {
324
+ val resultSet = statement.executeQuery(
325
+ " SELECT ARRAY(CAST(key AS STRING), value) FROM test_map LIMIT 1" )
326
+ resultSet.next()
327
+ resultSet.getString(1 )
328
+ }
329
+ }
330
+ }
293
331
}
0 commit comments