@@ -19,10 +19,9 @@ package org.apache.spark.sql.hive.thriftserver
1919
2020import java .io .File
2121import java .net .ServerSocket
22- import java .sql .{Date , DriverManager , Statement }
22+ import java .sql .{DriverManager , Statement }
2323import java .util .concurrent .TimeoutException
2424
25- import scala .collection .JavaConversions ._
2625import scala .collection .mutable .ArrayBuffer
2726import scala .concurrent .duration ._
2827import scala .concurrent .{Await , Promise }
@@ -52,15 +51,6 @@ import org.apache.spark.sql.hive.HiveShim
5251class HiveThriftServer2Suite extends FunSuite with Logging {
5352 Class .forName(classOf [HiveDriver ].getCanonicalName)
5453
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-
6454 def randomListeningPort = {
6555 // Let the system to choose a random available port to avoid collision with other parallel
6656 // builds.
@@ -155,8 +145,12 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
155145 }
156146 }
157147
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" -> " " )
160154
161155 Process (command, None , env : _* ).run(ProcessLogger (
162156 captureThriftServerOutput(" stdout" ),
@@ -200,12 +194,15 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
200194
201195 test(" Test JDBC query execution" ) {
202196 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)
209206
210207 queries.foreach(statement.execute)
211208
@@ -219,10 +216,14 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
219216
220217 test(" SPARK-3004 regression: result set containing NULL" ) {
221218 withJdbcStatement() { statement =>
219+ val dataFilePath =
220+ Thread .currentThread().getContextClassLoader.getResource(
221+ " data/files/small_kv_with_null.txt" )
222+
222223 val queries = Seq (
223224 " DROP TABLE IF EXISTS test_null" ,
224225 " 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 " )
226227
227228 queries.foreach(statement.execute)
228229
@@ -269,63 +270,24 @@ class HiveThriftServer2Suite extends FunSuite with Logging {
269270
270271 test(" SPARK-4292 regression: result set iterator issue" ) {
271272 withJdbcStatement() { statement =>
273+ val dataFilePath =
274+ Thread .currentThread().getContextClassLoader.getResource(" data/files/small_kv.txt" )
275+
272276 val queries = Seq (
273277 " DROP TABLE IF EXISTS test_4292" ,
274278 " 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 " )
276280
277281 queries.foreach(statement.execute)
278282
279283 val resultSet = statement.executeQuery(" SELECT key FROM test_4292" )
280284
281285 Seq (238 , 86 , 311 , 27 , 165 ).foreach { key =>
282286 resultSet.next()
283- assert(resultSet.getInt(1 ) === key)
287+ assert(resultSet.getInt(1 ) == key)
284288 }
285289
286290 statement.executeQuery(" DROP TABLE IF EXISTS test_4292" )
287291 }
288292 }
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- }
331293}
0 commit comments