fix(core): map DataFusion SchemaError to InvalidInput#6639
Merged
Xuanwo merged 1 commit intoMay 8, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Schema errors from DataFusion (e.g., a filter referencing an unknown
column or a projection naming a missing field) are user-input failures,
not internal lance failures. Mapping them to `Error::Schema` defeats
downstream consumers that pattern-match on `Error::InvalidInput` to
classify user errors — they end up reporting "internal error" for what
is plainly bad input.
Concrete impact: the lance-c FFI binding maps `Error::Schema` to its
`Internal` error code (catch-all), so a C/C++ caller passing
`lance_dataset_delete(ds, "no_such_column = 1", ...)` sees
`LANCE_ERR_INTERNAL` instead of `LANCE_ERR_INVALID_ARGUMENT`. Any other
binding that does the same kind of mapping (Python, Java, ...) is
similarly affected.
The other DataFusion variants that already route to `InvalidInput`
(`SQL`, `Plan`, `Configuration`) are user-input errors of the same
kind — `SchemaError` belongs in the same bucket.
Risk: any code that pattern-matches on `Error::Schema` to handle
DataFusion-derived schema errors will no longer match. A grep across
`lance`, `lance-index`, and `lance-datafusion` finds no such matches —
the two `Error::Schema { .. }` matches in
`lance-index/src/scalar/inverted/index.rs` are fed by lance-io's
internal `Error::schema(...)` calls, not by the DataFusion conversion,
and continue to work unchanged.
Adds a unit test that constructs a `DataFusionError::SchemaError`
directly and asserts the conversion produces `Error::InvalidInput`
with the offending column name preserved in the message.
f2451ee to
0a863ee
Compare
Xuanwo
approved these changes
May 8, 2026
Collaborator
|
Thank you for this change! |
3 tasks
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.
Summary
Schema errors from DataFusion (e.g. a filter referencing an unknown column, a projection naming a missing field) are user-input failures, not internal lance failures. Today they're mapped to
Error::Schema, which makes downstream consumers that pattern-match onError::InvalidInputfor user-facing error classification report them as "internal."This PR moves
DataFusionError::SchemaErrorinto the same bucket asSQL/Plan/Configuration, all of which already route toError::InvalidInput. Behaviorally these are the same kind of error — bad input from the caller — and they should classify the same way.Concrete impact
The C/C++ FFI binding (
lance-format/lance-c) mapsError::Schemato itsInternalerror code (catch-all), so a caller doing:sees
LANCE_ERR_INTERNALinstead ofLANCE_ERR_INVALID_ARGUMENT. Any binding doing the same kind of variant-based mapping (Python, Java, …) hits the same problem. lance-c #31 currently asserts the wrong code in its tests as a workaround — once this lands, that PR can flip its assertions toInvalidArgumentand the wart goes away.The path that produces this is straightforward:
Scanner::filterparses the SQL viaPlanner::parse_filter→filter.to_field(&df_schema)?→ DataFusion returnsDataFusionError::SchemaErrorfor unknown fields → today,Error::Schema { .. }. With this fix →Error::InvalidInput { .. }, with the column name preserved in the boxed source.Risk
Any code that pattern-matches on
Error::Schemato handle DataFusion-derived schema errors will no longer match.A grep across
rust/lance,rust/lance-index, andrust/lance-datafusionfinds two such matches, both inlance-index/src/scalar/inverted/index.rs(lines 1862, 1878). Both are fed bylance-io's internalError::schema(...)calls (not by the DataFusion conversion), and continue to behave unchanged.External consumers (Python bindings, Java bindings, lance-c) that classify
Error::Schemaas "internal" today will start classifying these errors as "invalid input" — which is the desired direction.Test plan
Adds a unit test (
test_datafusion_schema_error_is_invalid_input) that constructs aDataFusionError::SchemaError(SchemaError::FieldNotFound { ... })directly and asserts:ErrorisInvalidInput."missing_col") is preserved in the displayed error message.cargo fmt -p lance-core --checkclean.