You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/08 19:43:12 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2694: Combine limit and offset to `fetch` and `skip` and implement physical plan support

alamb commented on code in PR #2694:
URL: https://github.com/apache/arrow-datafusion/pull/2694#discussion_r892792342


##########
datafusion/sql/src/planner.rs:
##########
@@ -1212,57 +1206,59 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
     }
 
     /// Wrap a plan in a limit
-    fn limit(&self, input: LogicalPlan, limit: Option<SQLExpr>) -> Result<LogicalPlan> {
-        match limit {
-            Some(limit_expr) => {
-                let n = match self.sql_to_rex(
-                    limit_expr,
-                    input.schema(),
-                    &mut HashMap::new(),
-                )? {
-                    Expr::Literal(ScalarValue::Int64(Some(n))) => Ok(n as usize),
-                    _ => Err(DataFusionError::Plan(
-                        "Unexpected expression for LIMIT clause".to_string(),
-                    )),
-                }?;
-
-                LogicalPlanBuilder::from(input).limit(n)?.build()
-            }
-            _ => Ok(input),
-        }
-    }
-
-    /// Wrap a plan in a offset
-    fn offset(
+    fn limit(
         &self,
         input: LogicalPlan,
-        offset: Option<SQLOffset>,
+        skip: Option<SQLOffset>,
+        fetch: Option<SQLExpr>,
     ) -> Result<LogicalPlan> {
-        match offset {
-            Some(offset_expr) => {
-                let offset = match self.sql_to_rex(
-                    offset_expr.value,
+        if skip.is_none() && fetch.is_none() {
+            return Ok(input);
+        }
+
+        let skip = match skip {

Review Comment:
   This compiled for me:
   
   ```rust
   
           let skip = skip
               .map(|skip_expr| {
                   let skip = match self.sql_to_rex(
                       skip_expr.value,
                       input.schema(),
                       &mut HashMap::new(),
                   )? {
                       Expr::Literal(ScalarValue::Int64(Some(s))) => {
                           if s < 0 {
                               return Err(DataFusionError::Plan(format!(
                                   "Offset must be >= 0, '{}' was provided.",
                                   s
                               )));
                           }
                           Ok(s as usize)
                       }
                       _ => Err(DataFusionError::Plan(
                           "Unexpected expression in OFFSET clause".to_string(),
                       )),
                   }?;
                   Ok(skip)
               })
               .transpose()?;
   
   ```
   
   But I don't think it is all that much more readable than what you have in this PR



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org