Skip to content

Commit

Permalink
Fix regression from 21.12 where udfs defined in repl no longer worked (
Browse files Browse the repository at this point in the history
…#5030)

* Fix regression from 21.12 where udfs defined in repl no longer worked

Signed-off-by: Alessandro Bellina <abellina@nvidia.com>

* Update copyrights

* Add a comment explaining the use of Class.forName

* Update udf-compiler/src/main/scala/com/nvidia/spark/udf/LambdaReflection.scala

Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>

Co-authored-by: Gera Shegalov <gshegalov@nvidia.com>
  • Loading branch information
abellina and gerashegalov authored Mar 25, 2022
1 parent 75c4e87 commit 35d777e
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,6 @@ package com.nvidia.spark.udf

import java.lang.invoke.SerializedLambda

import com.nvidia.spark.rapids.ShimLoader
import javassist.{ClassClassPath, ClassPool, CtBehavior, CtClass, CtField, CtMethod}
import javassist.bytecode.{CodeIterator, ConstPool, Descriptor}

Expand Down Expand Up @@ -152,7 +151,17 @@ object LambdaReflection {
}

def getClass(name: String): Class[_] = {
ShimLoader.loadClass(name)
// Don't use ShimLoader.loadClass because in the REPL use case the classes
// compiled by REPL are accessible via the thread's context classloader,
// but not by the parent classloader detected by the plugin.
//
// This code is executed after the Plugin and ShimLoader has already been initialized.
// REPL classes are able to interact with the Plugin classes because the REPL
// Thread context classloader is a descendant of the Plugin classloader.

// scalastyle:off classforname
Class.forName(name, true, Thread.currentThread().getContextClassLoader)
// scalastyle:on classforname
}

def parseTypeSig(sig: String): Option[DataType] = {
Expand Down

0 comments on commit 35d777e

Please sign in to comment.