truongle1501 opened a new issue, #136: URL: https://github.com/apache/datafusion-iceberg/issues/136
# `iceberg-datafusion` enables DataFusion's default features (including `sql`), which breaks downstream crates that build DataFusion without SQL ## Summary The `iceberg-datafusion` library crate depends on `datafusion` **with default features on**. DataFusion's defaults include the `sql` feature. The library itself does not use any SQL functionality, but Cargo merges features across a whole build. So every project that depends on `iceberg-datafusion` gets DataFusion's SQL layer turned on, whether it wants it or not. For most users this is harmless. Some projects, however, deliberately build DataFusion **without** `sql`, and their code depends on that choice. Adding `iceberg-datafusion` to such a project makes it **fail to compile**. [Sail](https://github.com/lakehq/sail) is a real example (details below). **Proposal:** depend on `datafusion` with `default-features = false` in the workspace. Then let each crate in this repository opt in to only the features it needs. The library crate needs few or none; test and tooling crates keep `sql`. This is a manifest-only change, and it seems a good fit before the first crates.io release (#85). --- ## Background (for readers new to Cargo features) ### 1. DataFusion's `sql` feature DataFusion is split into optional parts called *features*. One of them, `sql`, adds the SQL front end: parsing SQL text and turning it into a query plan. It is turned on by default: - `default = [..., "sql"]`: [datafusion 55.2.0 `core/Cargo.toml` L58–L69](https://github.com/apache/datafusion/blob/55.2.0/datafusion/core/Cargo.toml#L58-L69) - What `sql` turns on: [L100](https://github.com/apache/datafusion/blob/55.2.0/datafusion/core/Cargo.toml#L100) (`datafusion-common/sql`, `datafusion-sql`, `sqlparser`, …) Without `sql`, DataFusion is still a complete query engine. Catalogs, tables, `DataFrame`, `LogicalPlanBuilder`, optimizers and execution all work. Only "turn SQL text into a plan" (`SessionContext::sql`, …) is missing. Engines that bring their own SQL dialect build plans directly and do not need DataFusion's SQL parser. ### 2. Turning `sql` on also adds an error variant With `sql` on, DataFusion's error type gains an extra variant: ```rust // datafusion-common/src/error.rs #[cfg(feature = "sql")] SQL(Box<ParserError>, Option<String>), ``` [datafusion 55.2.0 `common/src/error.rs` L85–L86](https://github.com/apache/datafusion/blob/55.2.0/datafusion/common/src/error.rs#L85-L86) So **the shape of `DataFusionError` depends on whether `sql` is on.** Code that lists every variant in a `match`, with no `_ =>` fallback, compiles only for one of the two shapes. ### 3. Cargo merges features across the whole build Cargo features are *additive* and *unified*. Within one build, each dependency is compiled **once**, with every feature that **any** crate in the build asks for. One crate cannot say "I want DataFusion without `sql`" if another crate in the same build asks for it, even indirectly through defaults. Cargo documentation: [Feature unification](https://doc.rust-lang.org/cargo/reference/features.html#feature-unification). So if a *library* turns default features on, every downstream user gets them too, and cannot turn them off. --- ## Where `iceberg-datafusion` turns on the defaults On `main` at [`865c081`](https://github.com/apache/datafusion-iceberg/tree/865c0813864fdf2d416eda4bd77d09ea1918f374): - The workspace declares `datafusion` without `default-features = false`: [`Cargo.toml` L37](https://github.com/apache/datafusion-iceberg/blob/865c0813864fdf2d416eda4bd77d09ea1918f374/Cargo.toml#L37) ```toml datafusion = "55.0.0" ``` - The library crate inherits that declaration as is: [`crates/datafusion/Cargo.toml` L36](https://github.com/apache/datafusion-iceberg/blob/865c0813864fdf2d416eda4bd77d09ea1918f374/crates/datafusion/Cargo.toml#L36) ```toml datafusion = { workspace = true } ``` When another project depends on `iceberg-datafusion` (from git or from crates.io), Cargo resolves `workspace = true` against this root manifest. The published crate therefore asks for `datafusion` **with all default features**, including `sql`. ## The library does not appear to need `sql` - The library provides `CatalogProvider`, `SchemaProvider`, `TableProvider`, scan, write and predicate conversion. None of these DataFusion APIs are behind the `sql` feature. - A code search of `crates/datafusion/src` for `.sql(`, `datafusion::sql` and `sqlparser` finds nothing. - The old SQL-using test helper (`test_utils`, which called `ctx.sql(...)`) has moved to the separate `crates/test-tools` crate. That crate is only a `[dev-dependency]`, so it is not part of downstream builds. The SQL parts of this repository (`test-tools`, `sqllogictest`, `playground`) genuinely need `sql`. They are separate crates and can opt in themselves. ## A real-world example: Sail [Sail](https://github.com/lakehq/sail) is a Spark-compatible engine built on DataFusion. It parses Spark SQL with its own parser, so it turned DataFusion's `sql` feature off on purpose: - lakehq/sail#1437 disabled DataFusion `sql` for all of Sail, and removed the now-unreachable `DataFusionError::SQL` arm. - Sail's workspace: [`Cargo.toml` L176](https://github.com/lakehq/sail/blob/ac4690078021cf2a5402dc5c7b38a886f1916c73/Cargo.toml#L176) has `datafusion = { version = "55.2.0", default-features = false, features = [...] }`, with no `sql`. - Sail converts `DataFusionError` with a `match` that lists every variant: [`sail-common-datafusion/src/error.rs` L160–L190](https://github.com/lakehq/sail/blob/ac4690078021cf2a5402dc5c7b38a886f1916c73/crates/sail-common-datafusion/src/error.rs#L160-L190). It has no `SQL` arm and no `_ =>` fallback. That is correct for a build without `sql`. When a project combines Sail with `iceberg-datafusion` (for example, to expose an Iceberg catalog to Spark clients), `iceberg-datafusion` turns `sql` on for the whole build. The `SQL` variant appears, and Sail stops compiling: ```text error[E0004]: non-exhaustive patterns: `&DataFusionError::SQL(_, _)` not covered --> .../sail/crates/sail-common-datafusion/src/error.rs:160:26 | 160 | return match e { | ^ pattern `&DataFusionError::SQL(_, _)` not covered ``` The downstream project cannot fix this: - Cargo has no way to **remove** a feature that a dependency turns on. - `[patch]` replaces a whole crate, but cannot change the features another crate asks for. The only workarounds are forking or vendoring `iceberg-datafusion`, or patching Sail. Both are heavy for what amounts to a one-line manifest setting. Sail is just one example. Any project that builds DataFusion without `sql`, and matches every `DataFusionError` variant or relies on `sql` being absent, is affected. More generally, a library that turns default features on also forces extra compile time and binary size (`sqlparser`, `datafusion-sql`, compression codecs, …) on every user. ## Minimal reproduction ```toml # Cargo.toml [package] name = "repro" version = "0.1.0" edition = "2024" [dependencies] datafusion-common = { version = "55", default-features = false } iceberg-datafusion = { git = "https://github.com/apache/datafusion-iceberg", rev = "865c0813864fdf2d416eda4bd77d09ea1918f374" } ``` ```rust // src/lib.rs: written for DataFusion without `sql`, exactly like Sail use datafusion_common::DataFusionError; pub fn kind(e: &DataFusionError) -> &'static str { match e { DataFusionError::ArrowError(..) => "arrow", DataFusionError::IoError(..) => "io", DataFusionError::NotImplemented(..) => "not_implemented", DataFusionError::Internal(..) => "internal", DataFusionError::Plan(..) => "plan", DataFusionError::Configuration(..) => "config", DataFusionError::SchemaError(..) => "schema", DataFusionError::Execution(..) => "execution", DataFusionError::ExecutionJoin(..) => "join", DataFusionError::ResourcesExhausted(..) => "resources", DataFusionError::External(..) => "external", DataFusionError::Context(..) => "context", DataFusionError::Substrait(..) => "substrait", DataFusionError::Diagnostic(..) => "diagnostic", DataFusionError::Collection(..) => "collection", DataFusionError::Shared(..) => "shared", DataFusionError::Ffi(..) => "ffi", #[cfg(any())] // placeholder: variants gated by other features omitted for brevity _ => unreachable!(), } } ``` - `cargo check` **fails** with `E0004 ... DataFusionError::SQL(_, _) not covered` (and possibly other feature-gated variants). - Remove the `iceberg-datafusion` line and it compiles. - `cargo tree -e features -i datafusion-common` shows the `sql` feature coming from `iceberg-datafusion → datafusion (default)`. ## Proposed change Manifest only; no Rust code changes are expected on `main`. ```diff # Cargo.toml (workspace) -datafusion = "55.0.0" +datafusion = { version = "55.0.0", default-features = false } # crates/datafusion/Cargo.toml (the published library) -datafusion = { workspace = true } +datafusion = { workspace = true, features = [ /* only what the library uses */ ] } # crates/test-tools, crates/sqllogictest, crates/playground (anything needing SQL) -datafusion = { workspace = true } +datafusion = { workspace = true, default-features = true } # or features = ["sql", ...] ``` To find the minimal feature list for the library: ```sh cargo check -p iceberg-datafusion --lib cargo tree -p iceberg-datafusion -e features -i datafusion-common # `sql` should not appear cargo test --workspace # SQL-using crates still get `sql` ``` DataFusion uses the same pattern: its own sub-crates depend on each other with `default-features = false`, for example `datafusion-expr` and `datafusion-functions-nested` in [`core/Cargo.toml`](https://github.com/apache/datafusion/blob/55.2.0/datafusion/core/Cargo.toml). Downstream engines such as Sail do the same. ## Why this is worth doing - **Reusability:** the integration can be used with any DataFusion feature set, including engines without SQL (Sail and similar). - **No downside for current users:** anyone who wants SQL already depends on `datafusion` directly with defaults. Cargo merges features, so they keep `sql`. - **Smaller builds:** downstream users who don't need SQL stop compiling `sqlparser` and `datafusion-sql`. - **Good timing:** doing this before the first crates.io release (#85) avoids changing published feature behavior later. I'm happy to open a PR for this if the approach sounds good. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
