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
Open
alamb
wants to merge
2
commits into
apache:main
Choose a base branch
from
alamb:alamb/doctest-upgrade-guide
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+48
−3
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 | ||
|
|
@@ -265,7 +274,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, | ||
|
|
@@ -276,6 +300,8 @@ let exec = SortMergeJoinExec::try_new( | |
| NullEquality::NullEqualsNothing, | ||
| )? | ||
| .with_null_aware(true)?; | ||
| # Ok(()) | ||
| # } | ||
| ``` | ||
|
|
||
| Both inputs must have a single partition when executed. | ||
|
|
@@ -284,6 +310,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, | ||
|
|
@@ -316,8 +344,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 | ||
|
|
@@ -343,6 +379,8 @@ 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(); | ||
|
|
@@ -370,6 +408,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, | ||
|
|
||
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