feat: typed DataFusionException hierarchy across the JNI boundary#81
Open
LantaoJin wants to merge 1 commit into
Open
feat: typed DataFusionException hierarchy across the JNI boundary#81LantaoJin wants to merge 1 commit into
LantaoJin wants to merge 1 commit into
Conversation
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?
DataFusionExceptionhierarchy across the JNI boundary #79 .Rationale for this change
Every error from the native side currently surfaces as a single
java.lang.RuntimeException.try_unwrap_or_throwinnative/src/errors.rscallsenv.throw_new("java/lang/RuntimeException", message)for everyErr(...)it sees, so aDataFusionError::Planand aDataFusionError::ResourcesExhaustedand aDataFusionError::IoErrorare indistinguishable on the Java side. Callers that want to retry on transient resource pressure but not on a malformed query plan have only the message string to discriminate on — fragile and brittle to upstream wording changes.This PR adds a typed Java exception hierarchy and routes each
DataFusionErrorvariant onto the matching subclass at the JNI layer, so callers cancatch (PlanException)/catch (ResourcesExhaustedException)selectively without scraping messages.The hierarchy is shallow on purpose. Multiple Rust variants fold into one Java class when they're the same kind of problem from the caller's standpoint (e.g.
IoError/ObjectStore/ParquetError/AvroErrorall surface asIoException). Variants with no clean caller-facing category —Internal,Substrait,Collection, plus any new variant a future DataFusion bump introduces — fall through to the parentDataFusionException. The mapping is the public contract; the underlying variant set is not.ArrowErrorgets per-variant treatment because it's a 21-variant grab bag that mixes IO with execution-time failures. Routing the wholeArrowErrorarm to a single class would put e.g.SELECT 1/0(ArrowError::DivideByZero) underIoException, which is wrong from a caller's standpoint. A smallclassify_arrowhelper splits the variants:IoError/IpcErrorgo toIoException,SchemaError/ParseErrorgo toPlanException, and the arithmetic / cast / compute variants go toExecutionException.Sequenced before upstream #55 ("propagate Java stack traces from JVM upcalls into
DataFusionError"), which is complementary: every subclass ships a(String, Throwable)constructor as the seam #55 plugs into for setting the original Java throwable ascause.What changes are included in this PR?
DataFusionException(extendsRuntimeException) plus 6 subclasses —PlanException,ExecutionException,ResourcesExhaustedException,IoException,NotImplementedException,ConfigurationException. Each ships(String)and(String, Throwable)constructors.errors.rsdowncasts the boxed error toDataFusionError, walks the cause chain via upstream'sDataFusionError::find_root(), and routes the root variant through aclassify()helper to the right Java class. The thrown message preserves the outer error's full chain so wrapping context isn't lost; only the class is picked from the inner variant.JniResult<T>is unchanged (Box<dyn Error + Send + Sync>) — every?site keeps working as-is. Rust panics surface as the parent class with apanic:prefix.find_root()matters because DataFusion can wrap aResourcesExhausted/Plan/ etc. inside anArrowError::ExternalError(...)or aContext(...)chain (upstream documents this exact shape). Withoutfind_root, those would land on the outer arm and be misclassified.ArrowErrorgets a dedicatedclassify_arrowhelper because the enum mixes IO (IoError,IpcError) with execution-time variants (DivideByZero,ArithmeticOverflow,ComputeError,CastError,InvalidArgumentError,MemoryError,External, …) and schema-shaped variants (SchemaError,ParseError). Each lands on the matching Java class instead of all collapsing toIoException.Internal,Substrait,Collection, future variants) fall through to the parent class.native/Cargo.tomladdsrlibalongsidecdylibto enable Rust unit tests that pin thefind_rootrouting behavior on synthetic wrapper chains; thecdylibartifact the JVM loads is unchanged.Are these changes tested?
Yes. 10 new Java tests + 7 new Rust unit tests.
Are there any user-facing changes?
No