Skip to content

Commit 13bf6c1

Browse files
committed
remove z.load() error for spark 1.2, spark 1.3
1 parent 1402df2 commit 13bf6c1

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

spark/src/main/java/org/apache/zeppelin/spark/dep/DependencyResolver.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ private void updateCompilerClassPath(URL[] urls) throws IllegalAccessException,
143143

144144
// Until spark 1.1.x
145145
// check https://github.com/apache/spark/commit/191d7cf2a655d032f160b9fa181730364681d0e7
146-
private void updateRuntimeClassPath(URL[] urls) throws SecurityException, IllegalAccessException,
147-
IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
146+
private void updateRuntimeClassPath_1_x(URL[] urls) throws SecurityException,
147+
IllegalAccessException, IllegalArgumentException,
148+
InvocationTargetException, NoSuchMethodException {
148149
ClassLoader cl = intp.classLoader().getParent();
149150
Method addURL;
150151
addURL = cl.getClass().getDeclaredMethod("addURL", new Class[] {URL.class});
@@ -154,6 +155,18 @@ private void updateRuntimeClassPath(URL[] urls) throws SecurityException, Illega
154155
}
155156
}
156157

158+
private void updateRuntimeClassPath_2_x(URL[] urls) throws SecurityException,
159+
IllegalAccessException, IllegalArgumentException,
160+
InvocationTargetException, NoSuchMethodException {
161+
ClassLoader cl = intp.classLoader().getParent();
162+
Method addURL;
163+
addURL = cl.getClass().getDeclaredMethod("addNewUrl", new Class[] {URL.class});
164+
addURL.setAccessible(true);
165+
for (URL url : urls) {
166+
addURL.invoke(cl, url);
167+
}
168+
}
169+
157170
private MergedClassPath<AbstractFile> mergeUrlsIntoClassPath(JavaPlatform platform, URL[] urls) {
158171
IndexedSeq<ClassPath<AbstractFile>> entries =
159172
((MergedClassPath<AbstractFile>) platform.classPath()).entries();
@@ -217,8 +230,11 @@ private void loadFromFs(String artifact, boolean addSparkContext) throws Excepti
217230

218231
intp.global().new Run();
219232

220-
updateRuntimeClassPath(new URL[] {jarFile.toURI().toURL()});
221-
updateCompilerClassPath(new URL[] {jarFile.toURI().toURL()});
233+
if (sc.version().startsWith("1.1")) {
234+
updateRuntimeClassPath_1_x(new URL[] {jarFile.toURI().toURL()});
235+
} else {
236+
updateRuntimeClassPath_2_x(new URL[] {jarFile.toURI().toURL()});
237+
}
222238

223239
if (addSparkContext) {
224240
sc.addJar(jarFile.getAbsolutePath());
@@ -261,7 +277,11 @@ private List<String> loadFromMvn(String artifact, Collection<String> excludes,
261277
}
262278

263279
intp.global().new Run();
264-
updateRuntimeClassPath(newClassPathList.toArray(new URL[0]));
280+
if (sc.version().startsWith("1.1")) {
281+
updateRuntimeClassPath_1_x(newClassPathList.toArray(new URL[0]));
282+
} else {
283+
updateRuntimeClassPath_2_x(newClassPathList.toArray(new URL[0]));
284+
}
265285
updateCompilerClassPath(newClassPathList.toArray(new URL[0]));
266286

267287
if (addSparkContext) {

0 commit comments

Comments
 (0)