Skip to content

Commit 093c348

Browse files
Andrew Oryhuai
Andrew Or
authored andcommitted
[SPARK-8498] [SQL] Add regression test for SPARK-8470
**Summary of the problem in SPARK-8470.** When using `HiveContext` to create a data frame of a user case class, Spark throws `scala.reflect.internal.MissingRequirementError` when it tries to infer the schema using reflection. This is caused by `HiveContext` silently overwriting the context class loader containing the user classes. **What this issue is about.** This issue adds regression tests for SPARK-8470, which is already fixed in #6891. We closed SPARK-8470 as a duplicate because it is a different manifestation of the same problem in SPARK-8368. Due to the complexity of the reproduction, this requires us to pre-package a special test jar and include it in the Spark project itself. I tested this with and without the fix in #6891 and verified that it passes only if the fix is present. Author: Andrew Or <andrew@databricks.com> Closes #6909 from andrewor14/SPARK-8498 and squashes the following commits: 5e9d688 [Andrew Or] Add regression test for SPARK-8470
1 parent b305e37 commit 093c348

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import org.apache.spark.{SparkConf, SparkContext}
19+
import org.apache.spark.sql.hive.HiveContext
20+
21+
/**
22+
* Entry point in test application for SPARK-8498.
23+
*
24+
* This file is not meant to be compiled during tests. It is already included
25+
* in a pre-built "test.jar" located in the same directory as this file.
26+
* This is included here for reference only and should NOT be modified without
27+
* rebuilding the test jar itself.
28+
*
29+
* This is used in org.apache.spark.sql.hive.HiveSparkSubmitSuite.
30+
*/
31+
object Main {
32+
def main(args: Array[String]) {
33+
println("Running regression test for SPARK-8498.")
34+
val sc = new SparkContext("local", "testing")
35+
val hc = new HiveContext(sc)
36+
// This line should not throw scala.reflect.internal.MissingRequirementError.
37+
// See SPARK-8470 for more detail.
38+
val df = hc.createDataFrame(Seq(MyCoolClass("1", "2", "3")))
39+
df.collect()
40+
println("Regression test for SPARK-8498 success!")
41+
}
42+
}
43+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/** Dummy class used in regression test SPARK-8498. */
19+
case class MyCoolClass(past: String, present: String, future: String)
20+
Binary file not shown.

sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveSparkSubmitSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class HiveSparkSubmitSuite
3535
with ResetSystemProperties
3636
with Timeouts {
3737

38+
// TODO: rewrite these or mark them as slow tests to be run sparingly
39+
3840
def beforeAll() {
3941
System.setProperty("spark.testing", "true")
4042
}
@@ -65,6 +67,17 @@ class HiveSparkSubmitSuite
6567
runSparkSubmit(args)
6668
}
6769

70+
test("SPARK-8498: MissingRequirementError during reflection") {
71+
// This test uses a pre-built jar to test SPARK-8498. In a nutshell, this test creates
72+
// a HiveContext and uses it to create a data frame from an RDD using reflection.
73+
// Before the fix in SPARK-8470, this results in a MissingRequirementError because
74+
// the HiveContext code mistakenly overrides the class loader that contains user classes.
75+
// For more detail, see sql/hive/src/test/resources/regression-test-SPARK-8498/*scala.
76+
val testJar = "sql/hive/src/test/resources/regression-test-SPARK-8498/test.jar"
77+
val args = Seq("--class", "Main", testJar)
78+
runSparkSubmit(args)
79+
}
80+
6881
// NOTE: This is an expensive operation in terms of time (10 seconds+). Use sparingly.
6982
// This is copied from org.apache.spark.deploy.SparkSubmitSuite
7083
private def runSparkSubmit(args: Seq[String]): Unit = {

0 commit comments

Comments
 (0)