fix: Use thread context classloader for Iceberg class loading#3738
Open
karuppayya wants to merge 1 commit intoapache:mainfrom
Open
fix: Use thread context classloader for Iceberg class loading#3738karuppayya wants to merge 1 commit intoapache:mainfrom
karuppayya wants to merge 1 commit intoapache:mainfrom
Conversation
Author
9cc9c54 to
36c9eb5
Compare
36c9eb5 to
9c440ad
Compare
parthchandra
approved these changes
Mar 19, 2026
Contributor
parthchandra
left a comment
There was a problem hiding this comment.
lgtm. One minor comment. Also would be good to get @mbutrovich's approval
| * @return | ||
| * The loaded Class object | ||
| */ | ||
| def loadClass(className: String): Class[_] = { |
Contributor
There was a problem hiding this comment.
If there is a class loading error, it would be useful to log which loader was used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #3737
Rationale for this change
Comet uses
Class.forName(className)to reflectively load Iceberg classes.The single-argument
Class.forNameuses the classloader of the calling class, not the thread context classloader.When the Comet JAR is placed in Spark's
jars/folder, it is loaded by the system classloader.However, Iceberg classes may be bundled inside the user's application JAR(as uber jar), which is loaded by Spark's application classloader .
Since parent classloaders cannot see classes loaded by child classloaders,
Class.forNamefrom Comet's code fails withClassNotFoundException.(
SparkClassUtils.classForNameI guess does the same)What changes are included in this PR?
IcebergReflection.loadClass()helper that resolves classes via the thread context classloader (falling back to the default if null).Class.forNamecalls inIcebergReflectionandCometIcebergNativeScanwith the new helper method.How are these changes tested?
Verified in a deployment where the Comet JAR is in Spark's
jars/folder and Iceberg is bundled in the application uber JAR and ran few SQLs which involved reading from Iceberg.