Repository navigation
docs: Run the 57.0.0 upgrade guide examples as doctests #27916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
328e7c8
docs: Run the 57.0.0 upgrade guide examples as doctests
alamb b5471c8
Explain why two upgrade guide examples are not doctests
alamb 9f432fe
Run the `CreateFunction` "After" upgrade guide example as a doctest
alamb 4db46dd
Merge remote-tracking branch 'apache/main' into alamb/doctest-upgrade…
alamb b872c16
Split the catalog lookup upgrade guide examples so the 57.0.0 code ru…
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
@@ -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. | ||
|
|
@@ -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, | ||
|
|
@@ -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 | ||
|
|
@@ -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. | ||
|
|
@@ -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, | ||
|
|
@@ -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 | ||
|
|
||
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.
There was a problem hiding this comment.
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