goldmedal commented on code in PR #13028:
URL: https://github.com/apache/datafusion/pull/13028#discussion_r1809054261
##########
datafusion/optimizer/src/eliminate_limit.rs:
##########
@@ -63,17 +63,23 @@ impl OptimizerRule for EliminateLimit {
> {
match plan {
LogicalPlan::Limit(limit) => {
- if let Some(fetch) = limit.fetch {
- if fetch == 0 {
+ // Only supports rewriting for literal fetch
+ let FetchType::Literal(fetch) = limit.get_fetch_type()? else {
+ return Ok(Transformed::no(LogicalPlan::Limit(limit)));
+ };
+
+ if let Some(v) = fetch {
+ if v == 0 {
return Ok(Transformed::yes(LogicalPlan::EmptyRelation(
EmptyRelation {
produce_one_row: false,
schema: Arc::clone(limit.input.schema()),
},
)));
}
- } else if limit.skip == 0 {
- // input also can be Limit, so we should apply again.
+ } else if matches!(limit.get_skip_type()?,
SkipType::Literal(0)) {
+ // If fetch is `None` and skip is 0, then Limit takes no
effect and
+ // we can remove it. Its input also can be Limit, so we
should apply again.
return Ok(self
.rewrite(Arc::unwrap_or_clone(limit.input), _config)
.unwrap());
Review Comment:
```suggestion
.rewrite(Arc::unwrap_or_clone(limit.input),
_config)?);
```
Just noticed this point. It's better to return an error instead of a panic.
Could you help to improve it?
##########
datafusion/expr/src/expr_rewriter/mod.rs:
##########
@@ -308,7 +308,10 @@ impl NamePreserver {
Self {
// The schema of Filter and Join nodes comes from their inputs
rather than their output expressions,
Review Comment:
```suggestion
// The schema of Filter, Join, and Limit nodes comes from their
inputs rather than their output expressions,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]