-
Notifications
You must be signed in to change notification settings - Fork 72
Port sort logic to the datafusion planner #505
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
charlesbluca
merged 20 commits into
dask-contrib:datafusion-sql-planner
from
ayushdg:datafusion-dsql-sort
May 13, 2022
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
863fcb3
Implement PySort logical_plan
ayushdg f565c2a
Add a sort plan accessor to the logical plan
ayushdg 75933b8
Python: Update the sort plugin
ayushdg e882408
Python: Uncomment tests
ayushdg 5f7e8c6
Merge branch 'datafusion-sql-planner' of github.com:dask-contrib/dask…
ayushdg b6c534e
PLanner: Update accessor pattern for concrete logical plan implementa…
ayushdg 82b4234
Test: Address review comments
ayushdg ee99096
add support for expr_to_field for Expr::Sort expressions
andygrove 5d1a561
Merge branch 'datafusion-sql-planner' of github.com:dask-contrib/dask…
ayushdg 2932a28
Merge commit 'refs/pull/515/head' of github.com:dask-contrib/dask-sql…
ayushdg 05c6a85
Planner: Update sort expr utilities and import cleanup
ayushdg f9f569e
Python: Re-enable skipped sort tests
ayushdg 0840870
Merge branch 'datafusion-sql-planner' of github.com:dask-contrib/dask…
ayushdg 8d81c44
Python: Handle case where orderby column name is an alias
ayushdg 0a75c32
Apply suggestions from code review
ayushdg 74d3451
Style: Fix formatting
ayushdg 8aaf8fe
Merge branch 'datafusion-sql-planner' of github.com:dask-contrib/dask…
ayushdg 6bbb8d7
Planner: Remove public scope for LogicalPlan import
ayushdg 36b8460
Python: Add more complex sort tests with alias that error right now
ayushdg 315fad2
Python: Remove old commented code
ayushdg 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
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| use crate::expression::PyExpr; | ||
|
|
||
| use datafusion::logical_expr::{logical_plan::Sort, Expr, LogicalPlan}; | ||
| use pyo3::prelude::*; | ||
|
|
||
| #[pyclass(name = "Sort", module = "dask_planner", subclass)] | ||
| #[derive(Clone)] | ||
| pub struct PySort { | ||
| sort: Sort, | ||
| } | ||
|
|
||
| impl PySort { | ||
| /// Returns if a sort expressions denotes an ascending sort | ||
| fn is_ascending(&self, expr: &Expr) -> Result<bool, PyErr> { | ||
| match expr { | ||
| Expr::Sort { asc, .. } => Ok(asc.clone()), | ||
| _ => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!( | ||
| "Provided Expr {:?} is not a sort type", | ||
| expr | ||
| ))), | ||
| } | ||
| } | ||
| /// Returns if nulls should be placed first in a sort expression | ||
| fn is_nulls_first(&self, expr: &Expr) -> Result<bool, PyErr> { | ||
| match &expr { | ||
| Expr::Sort { nulls_first, .. } => Ok(nulls_first.clone()), | ||
| _ => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!( | ||
| "Provided Expr {:?} is not a sort type", | ||
| expr | ||
| ))), | ||
| } | ||
| } | ||
| } | ||
| #[pymethods] | ||
| impl PySort { | ||
| /// Returns a Vec of the sort expressions | ||
| #[pyo3(name = "getCollation")] | ||
| pub fn sort_expressions(&self) -> PyResult<Vec<PyExpr>> { | ||
| let mut sort_exprs: Vec<PyExpr> = Vec::new(); | ||
| for expr in &self.sort.expr { | ||
| sort_exprs.push(PyExpr::from(expr.clone(), Some(self.sort.input.clone()))); | ||
| } | ||
| Ok(sort_exprs) | ||
| } | ||
|
|
||
| #[pyo3(name = "getAscending")] | ||
| pub fn get_ascending(&self) -> PyResult<Vec<bool>> { | ||
| self.sort | ||
| .expr | ||
| .iter() | ||
| .map(|sortexpr| self.is_ascending(sortexpr)) | ||
| .collect::<Result<Vec<_>, _>>() | ||
| } | ||
| #[pyo3(name = "getNullsFirst")] | ||
| pub fn get_nulls_first(&self) -> PyResult<Vec<bool>> { | ||
| self.sort | ||
| .expr | ||
| .iter() | ||
| .map(|sortexpr| self.is_nulls_first(sortexpr)) | ||
| .collect::<Result<Vec<_>, _>>() | ||
| } | ||
| } | ||
|
|
||
| impl From<LogicalPlan> for PySort { | ||
| fn from(logical_plan: LogicalPlan) -> PySort { | ||
| match logical_plan { | ||
| LogicalPlan::Sort(srt) => PySort { sort: srt }, | ||
| _ => panic!("something went wrong here"), | ||
| } | ||
| } | ||
| } | ||
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
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.
No need to change just for reference #510