@@ -19,10 +19,9 @@ 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 .{Date , DriverManager , Statement }
22
+ import java .sql .{DriverManager , Statement }
23
23
import java .util .concurrent .TimeoutException
24
24
25
- import scala .collection .JavaConversions ._
26
25
import scala .collection .mutable .ArrayBuffer
27
26
import scala .concurrent .duration ._
28
27
import scala .concurrent .{Await , Promise }
@@ -52,15 +51,6 @@ import org.apache.spark.sql.hive.HiveShim
52
51
class HiveThriftServer2Suite extends FunSuite with Logging {
53
52
Class .forName(classOf [HiveDriver ].getCanonicalName)
54
53
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
-
64
54
def randomListeningPort = {
65
55
// Let the system to choose a random available port to avoid collision with other parallel
66
56
// builds.
@@ -155,8 +145,12 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
155
145
}
156
146
}
157
147
158
- // Resets SPARK_TESTING to avoid loading Log4J configurations in testing class paths
159
- val env = Seq (" SPARK_TESTING" -> " 0" )
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" -> " " )
160
154
161
155
Process (command, None , env : _* ).run(ProcessLogger (
162
156
captureThriftServerOutput(" stdout" ),
@@ -200,12 +194,15 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
200
194
201
195
test(" Test JDBC query execution" ) {
202
196
withJdbcStatement() { statement =>
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" )
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)
209
206
210
207
queries.foreach(statement.execute)
211
208
@@ -219,10 +216,14 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
219
216
220
217
test(" SPARK-3004 regression: result set containing NULL" ) {
221
218
withJdbcStatement() { statement =>
219
+ val dataFilePath =
220
+ Thread .currentThread().getContextClassLoader.getResource(
221
+ " data/files/small_kv_with_null.txt" )
222
+
222
223
val queries = Seq (
223
224
" DROP TABLE IF EXISTS test_null" ,
224
225
" CREATE TABLE test_null(key INT, val STRING)" ,
225
- s " LOAD DATA LOCAL INPATH ' ${ TestData .smallKvWithNull} ' OVERWRITE INTO TABLE test_null " )
226
+ s " LOAD DATA LOCAL INPATH ' $dataFilePath ' OVERWRITE INTO TABLE test_null " )
226
227
227
228
queries.foreach(statement.execute)
228
229
@@ -269,63 +270,24 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
269
270
270
271
test(" SPARK-4292 regression: result set iterator issue" ) {
271
272
withJdbcStatement() { statement =>
273
+ val dataFilePath =
274
+ Thread .currentThread().getContextClassLoader.getResource(" data/files/small_kv.txt" )
275
+
272
276
val queries = Seq (
273
277
" DROP TABLE IF EXISTS test_4292" ,
274
278
" CREATE TABLE test_4292(key INT, val STRING)" ,
275
- s " LOAD DATA LOCAL INPATH ' ${ TestData .smallKv} ' OVERWRITE INTO TABLE test_4292 " )
279
+ s " LOAD DATA LOCAL INPATH ' $dataFilePath ' OVERWRITE INTO TABLE test_4292 " )
276
280
277
281
queries.foreach(statement.execute)
278
282
279
283
val resultSet = statement.executeQuery(" SELECT key FROM test_4292" )
280
284
281
285
Seq (238 , 86 , 311 , 27 , 165 ).foreach { key =>
282
286
resultSet.next()
283
- assert(resultSet.getInt(1 ) === key)
287
+ assert(resultSet.getInt(1 ) == key)
284
288
}
285
289
286
290
statement.executeQuery(" DROP TABLE IF EXISTS test_4292" )
287
291
}
288
292
}
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
- }
331
293
}
0 commit comments