Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions datafusion/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,12 @@ doc_comment::doctest!(
library_user_guide_working_with_exprs
);

#[cfg(doctest)]
doc_comment::doctest!(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this runs the examples as real doc tests

"../../../docs/source/library-user-guide/upgrading/index.md",
library_user_guide_upgrading
);

#[cfg(doctest)]
doc_comment::doctest!(
"../../../docs/source/contributor-guide/api-health.md",
Expand Down
75 changes: 70 additions & 5 deletions docs/source/library-user-guide/upgrading/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,18 @@ has fields. Before, this could panic or return another column's values.
Start from `Statistics::new_unknown`, or project a child's statistics with
`Statistics::project` if the plan changes its columns:

```rust,ignore
```rust
# use datafusion::arrow::datatypes::SchemaRef;
# use datafusion::common::{Statistics, stats::Precision};
# struct MyExec { schema: SchemaRef }
# impl MyExec {
# fn schema(&self) -> SchemaRef { self.schema.clone() }
# fn statistics(&self, num_rows: usize) -> Statistics {
let statistics = Statistics::new_unknown(&self.schema())
.with_num_rows(Precision::Exact(num_rows));
# statistics
# }
# }
```

### Materialized CTE scans have a projection
Expand Down Expand Up @@ -317,7 +326,22 @@ The existing seven-argument `SortMergeJoinExec::try_new` continues
to create a non-null-aware join. Enable null-aware semantics with
`.with_null_aware(true)?`:

```rust,ignore
```rust
# use std::sync::Arc;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

add various stuff needed to make it compile and run

# use datafusion::arrow::compute::SortOptions;
# use datafusion::arrow::datatypes::{DataType, Field, Schema};
# use datafusion::common::{JoinType, NullEquality};
# use datafusion::error::Result;
# use datafusion::physical_expr::expressions::Column;
# use datafusion::physical_plan::ExecutionPlan;
# use datafusion::physical_plan::empty::EmptyExec;
# use datafusion::physical_plan::joins::SortMergeJoinExec;
# use datafusion::physical_plan::joins::utils::JoinOn;
# fn main() -> Result<()> {
# let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int32, true)]));
# let left: Arc<dyn ExecutionPlan> = Arc::new(EmptyExec::new(Arc::clone(&schema)));
# let right: Arc<dyn ExecutionPlan> = Arc::new(EmptyExec::new(schema));
# let on: JoinOn = vec![(Arc::new(Column::new("a", 0)), Arc::new(Column::new("a", 0)))];
let exec = SortMergeJoinExec::try_new(
left,
right,
Expand All @@ -328,6 +352,8 @@ let exec = SortMergeJoinExec::try_new(
NullEquality::NullEqualsNothing,
)?
.with_null_aware(true)?;
# Ok(())
# }
```

Both inputs must have a single partition when executed.
Expand All @@ -336,6 +362,8 @@ The generated protobuf `SortMergeJoinExecNode` type has a new
`null_aware` field. Exhaustive struct literals must initialize it;
`false` preserves the previous behavior:

<!-- Not run as a doctest: `datafusion-proto` is not a dependency of the `datafusion` crate, which runs the examples on this page -->

```rust,ignore
let node = SortMergeJoinExecNode {
left,
Expand Down Expand Up @@ -368,8 +396,16 @@ computed expression as not determined.

**Migration guide:**

```rust,ignore
```rust
# use datafusion::common::{
# DFSchema, aggregate_functional_dependencies,
# aggregate_functional_dependencies_with_computed_inputs,
# };
# let (input_schema, aggr_schema) = (&DFSchema::empty(), &DFSchema::empty());
# let group_by_input_indices: Vec<Option<usize>> = vec![];
# let computed_input_indices: Vec<Option<Vec<usize>>> = vec![];
// Before
# #[expect(deprecated)]
let deps = aggregate_functional_dependencies(input_schema, &group_by_input_indices, aggr_schema);

// After
Expand All @@ -395,16 +431,26 @@ the name `""`.

**Migration guide:**

<!-- Not run as a doctest: the "Before" code uses fields that were removed and so does not compile -->

```rust,ignore
// Before
let arg_types: Vec<DataType> = args.iter().map(|a| a.data_type.clone()).collect();
let return_type: Option<DataType> = definition.return_type;
```

<!-- But can run the after -->

```rust
# use datafusion::arrow::datatypes::DataType;
# use datafusion::logical_expr::{CreateFunction, OperateFunctionArg};
# fn example(args: &[OperateFunctionArg], definition: CreateFunction) {
// After
let arg_types: Vec<DataType> = args.iter().map(|a| a.field.data_type().clone()).collect();
let return_type: Option<DataType> = definition
.return_field
.map(|field| field.data_type().clone());
# }
```

`CreateFunction::try_new` takes `Option<FieldRef>` for the return type.
Expand All @@ -422,6 +468,7 @@ Code that constructs these structs with an exhaustive struct literal must add
the field or use `..Default::default()`. Builder methods are unaffected:

```rust
# use datafusion::prelude::CsvReadOptions;
// 56.0.0
let options = CsvReadOptions {
has_header: true,
Expand Down Expand Up @@ -462,30 +509,48 @@ failed. That was indistinguishable from "no schemas", "schema not found", or

Implementations that cannot fail can wrap their existing return value in `Ok`:

```rust
<!-- Not run as a doctest: the 56.0.0 code is a trait method with a signature that no longer exists -->

```rust,ignore
// 56.0.0
fn table_exist(&self, name: &str) -> bool {
self.tables.contains_key(name)
}
```

```rust
# use datafusion::error::Result;
# use std::collections::HashMap;
# struct MySchema { tables: HashMap<String, ()> }
# impl MySchema {
// 57.0.0
fn table_exist(&self, name: &str) -> Result<bool> {
Ok(self.tables.contains_key(name))
}
# }
```

Callers need to handle the error, typically with `?`:

```rust
<!-- Not run as a doctest: the 56.0.0 code does not compile now that the methods return `Result` -->

```rust,ignore
// 56.0.0
if let Some(schema) = catalog.schema("public") {
for table in schema.table_names() { /* ... */ }
}
```

```rust
# use datafusion::catalog::CatalogProvider;
# use datafusion::error::Result;
# fn example(catalog: &dyn CatalogProvider) -> Result<()> {
// 57.0.0
if let Some(schema) = catalog.schema("public")? {
for table in schema.table_names()? { /* ... */ }
}
# Ok(())
# }
```

The FFI wrappers (`FFI_CatalogProvider` and `FFI_SchemaProvider`) carry these
Expand Down