Skip to content

fix(core): map DataFusion SchemaError to InvalidInput#6639

Merged
Xuanwo merged 1 commit into
lance-format:mainfrom
jja725:fix/datafusion-schema-error-as-invalid-input
May 8, 2026
Merged

fix(core): map DataFusion SchemaError to InvalidInput#6639
Xuanwo merged 1 commit into
lance-format:mainfrom
jja725:fix/datafusion-schema-error-as-invalid-input

Conversation

@jja725
Copy link
Copy Markdown
Contributor

@jja725 jja725 commented Apr 29, 2026

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 on Error::InvalidInput for user-facing error classification report them as "internal."

This PR moves DataFusionError::SchemaError into the same bucket as SQL/Plan/Configuration, all of which already route to Error::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) maps Error::Schema to its Internal error code (catch-all), so a caller doing:

lance_dataset_delete(ds, "no_such_column = 1", NULL);

sees LANCE_ERR_INTERNAL instead of LANCE_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 to InvalidArgument and the wart goes away.

The path that produces this is straightforward: Scanner::filter parses the SQL via Planner::parse_filterfilter.to_field(&df_schema)? → DataFusion returns DataFusionError::SchemaError for 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::Schema to handle DataFusion-derived schema errors will no longer match.

A grep across rust/lance, rust/lance-index, and rust/lance-datafusion finds two such matches, both in lance-index/src/scalar/inverted/index.rs (lines 1862, 1878). Both are fed by lance-io's internal Error::schema(...) calls (not by the DataFusion conversion), and continue to behave unchanged.

External consumers (Python bindings, Java bindings, lance-c) that classify Error::Schema as "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 a DataFusionError::SchemaError(SchemaError::FieldNotFound { ... }) directly and asserts:

  1. The converted Error is InvalidInput.
  2. The offending column name ("missing_col") is preserved in the displayed error message.
$ cargo test -p lance-core --features datafusion test_datafusion_schema_error_is_invalid_input
test error::test::test_datafusion_schema_error_is_invalid_input ... ok
test result: ok. 1 passed; 0 failed

cargo fmt -p lance-core --check clean.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added the bug Something isn't working label Apr 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-core/src/error.rs 92.30% 1 Missing ⚠️

📢 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.
@jja725 jja725 force-pushed the fix/datafusion-schema-error-as-invalid-input branch from f2451ee to 0a863ee Compare May 7, 2026 23:41
@Xuanwo
Copy link
Copy Markdown
Collaborator

Xuanwo commented May 8, 2026

Thank you for this change!

@Xuanwo Xuanwo merged commit b7ff253 into lance-format:main May 8, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants