-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(proto): support expressions in LIMIT skip and fetch #24159
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
karpenkoag
wants to merge
1
commit into
apache:main
Choose a base branch
from
tarantool:a.karpenko/allow-evaluated-expr-in-logical-plan
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.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,8 @@ use crate::error::{DataFusionError, Result}; | |
| use crate::execution::context::ExecutionProps; | ||
| use crate::logical_expr::utils::generate_sort_key; | ||
| use crate::logical_expr::{ | ||
| Aggregate, EmptyRelation, Join, Projection, Sort, TableScan, Unnest, Values, Window, | ||
| Aggregate, EmptyRelation, Join, Limit, Projection, Sort, TableScan, Unnest, Values, | ||
| Window, | ||
| }; | ||
| use crate::logical_expr::{Expr, LogicalPlan, PlanType, Repartition}; | ||
| use crate::physical_expr::{ | ||
|
|
@@ -88,12 +89,14 @@ use datafusion_expr::logical_plan::builder::wrap_projection_for_join_if_necessar | |
| use datafusion_expr::physical_planning_context::{ | ||
| PhysicalPlanningContext, ScalarSubqueryResults, SubqueryIndex, | ||
| }; | ||
| use datafusion_expr::simplify::SimplifyContext; | ||
| use datafusion_expr::utils::{expr_to_columns, split_conjunction}; | ||
| use datafusion_expr::{ | ||
| Analyze, BinaryExpr, DescribeTable, DmlStatement, Explain, ExplainFormat, Extension, | ||
| FetchType, Filter, JoinType, Operator, RecursiveQuery, SkipType, StringifiedPlan, | ||
| WindowFrame, WindowFrameBound, WriteOp, | ||
| }; | ||
| use datafusion_optimizer::simplify_expressions::ExprSimplifier; | ||
| use datafusion_physical_expr::aggregate::{ | ||
| AggregateFunctionExpr, LoweredAggregate, LoweredAggregateBuilder, | ||
| }; | ||
|
|
@@ -1216,6 +1219,26 @@ impl DefaultPhysicalPlanner { | |
| } | ||
| LogicalPlan::SubqueryAlias(_) => children.one()?, | ||
| LogicalPlan::Limit(limit) => { | ||
| // Try to evaluate skip and fetch expressions. | ||
| let context = SimplifyContext::builder().build(); | ||
| let simplifier = ExprSimplifier::new(context); | ||
|
|
||
| let skip = match &limit.skip { | ||
| Some(expr) => Some(Box::new(simplifier.simplify(*expr.clone())?)), | ||
| None => None, | ||
| }; | ||
|
|
||
| let fetch = match &limit.fetch { | ||
| Some(expr) => Some(Box::new(simplifier.simplify(*expr.clone())?)), | ||
| None => None, | ||
| }; | ||
|
Comment on lines
+1226
to
+1234
Contributor
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. Can we avoid code duplication here? e.g. create a closure. |
||
|
|
||
| let limit = Limit { | ||
| input: Arc::clone(&limit.input), | ||
| skip, | ||
| fetch, | ||
| }; | ||
|
|
||
| let input = children.one()?; | ||
| let SkipType::Literal(skip) = limit.get_skip_type()? else { | ||
| return not_impl_err!( | ||
|
|
||
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3674,7 +3674,8 @@ pub struct Limit { | |||||
| pub enum SkipType { | ||||||
| /// The skip expression is a literal value. | ||||||
| Literal(usize), | ||||||
| /// Currently only supports expressions that can be folded into constants. | ||||||
| //// Currently supports all expressions that can be evaluated. | ||||||
| /// UnsupportedExpr means that the expression is not considered by the analyzer/optimizer. | ||||||
| UnsupportedExpr, | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -3683,7 +3684,8 @@ pub enum FetchType { | |||||
| /// The fetch expression is a literal value. | ||||||
| /// `Literal(None)` means the fetch expression is not provided. | ||||||
| Literal(Option<usize>), | ||||||
| /// Currently only supports expressions that can be folded into constants. | ||||||
| //// Currently supports all expressions that can be evaluated. | ||||||
| /// UnsupportedExpr means that the expression is not considered by the analyzer/optimizer. | ||||||
|
Contributor
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.
Suggested change
|
||||||
| UnsupportedExpr, | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
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
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.
Let's add SLT to test these changes.