fn limit(
        &self,
        input: &PlanNode,
        limit: &Option<sqlparser::ast::Expr>,
        offset: &Option<sqlparser::ast::Offset>,
        select: Option<&sqlparser::ast::Select>,
    ) -> Result<PlanNode> {
        match (limit, offset) {
            (None, None) => Ok(input.clone()),
            (limit, offset) => {
                let n = limit
                    .as_ref()
                    .map(|limit_expr| {
                        self.sql_to_rex(limit_expr, &input.schema(), select)
                            .and_then(|limit_expr| match limit_expr {
                                Expression::Literal { value, .. } => Ok(value.as_u64()? as usize),
                                _ => Err(ErrorCode::SyntaxException(format!(
                                    "Unexpected expression for LIMIT clause: {:?}",
                                    limit_expr
                                ))),
                            })
                    })
                    .transpose()?;

                let offset = offset
                    .as_ref()
                    .map(|offset| {
                        let offset_expr = &offset.value;
                        self.sql_to_rex(offset_expr, &input.schema(), select)
                            .and_then(|offset_expr| match offset_expr {
                                Expression::Literal { value, .. } => Ok(value.as_u64()? as usize),
                                _ => Err(ErrorCode::SyntaxException(format!(
                                    "Unexpected expression for OFFSET clause: {:?}",
                                    offset_expr,
                                ))),
                            })
                    })
                    .transpose()?
                    .unwrap_or(0);

                PlanBuilder::from(input)
                    .limit_offset(n, offset)
                    .and_then(|builder| builder.build())
            }
        }
    }
/// Wrap a plan in a limit
Wrap a plan in a limit
Wrap a plan in a limit
fn limit(
        &self,
        input: &PlanNode,
        limit: &Option<sqlparser::ast::Expr>,
        offset: &Option<sqlparser::ast::Offset>,
        select: Option<&sqlparser::ast::Select>,
    ) -> Result<PlanNode> {
        match (limit, offset) {
            (None, None) => Ok(input.clone()),
            (limit, offset) => {
                let n = limit
                    .as_ref()
                    .map(|limit_expr| {
                        self.sql_to_rex(limit_expr, &input.schema(), select)
                            .and_then(|limit_expr| match limit_expr {
                                Expression::Literal { value, .. } => Ok(value.as_u64()? as usize),
                                _ => Err(ErrorCode::SyntaxException(format!(
                                    "Unexpected expression for LIMIT clause: {:?}",
                                    limit_expr
                                ))),
                            })
                    })
                    .transpose()?;
                let offset = offset
                    .as_ref()
                    .map(|offset| {
                        let offset_expr = &offset.value;
                        self.sql_to_rex(offset_expr, &input.schema(), select)
                            .and_then(|offset_expr| match offset_expr {
                                Expression::Literal { value, .. } => Ok(value.as_u64()? as usize),
                                _ => Err(ErrorCode::SyntaxException(format!(
                                    "Unexpected expression for OFFSET clause: {:?}",
                                    offset_expr,
                                ))),
                            })
                    })
                    .transpose()?
                    .unwrap_or(0);
                PlanBuilder::from(input)
                    .limit_offset(n, offset)
                    .and_then(|builder| builder.build())
            }
        }
    }
fn limit ( & self , input : & PlanNode , limit : & Option < sqlparser :: ast :: Expr > , offset : & Option < sqlparser :: ast :: Offset > , select : Option < & sqlparser :: ast :: Select > , ) -> Result < PlanNode > { match ( limit , offset ) { ( None , None ) => Ok ( input . clone ( ) ) , ( limit , offset ) => { let n = limit . as_ref ( ) . map ( | limit_expr | { self . sql_to_rex ( limit_expr , & input . schema ( ) , select ) . and_then ( | limit_expr | match limit_expr { Expression :: Literal { value , .. } => Ok ( value . as_u64 ( ) ? as usize ) , _ => Err ( ErrorCode :: SyntaxException ( format ! ( " " limit_expr ) ) ) , } ) } ) . transpose ( ) ? ; let offset = offset . as_ref ( ) . map ( | offset | { let offset_expr = & offset . value ; self . sql_to_rex ( offset_expr , & input . schema ( ) , select ) . and_then ( | offset_expr | match offset_expr { Expression :: Literal { value , .. } => Ok ( value . as_u64 ( ) ? as usize ) , _ => Err ( ErrorCode :: SyntaxException ( format ! ( " " offset_expr ) ) ) , } ) } ) . transpose ( ) ? . unwrap_or ( 0 ) ; PlanBuilder :: from ( input ) . limit_offset ( n , offset ) . and_then ( | builder | builder . build ( ) ) } } }
Wrap a plan in a limit
Wrap a plan in a limit
&self
input
&PlanNode
limit
&Option<sqlparser::ast::Expr>
offset
&Option<sqlparser::ast::Offset>
select
Option<&sqlparser::ast::Select>
&self
input
&PlanNode
limit
&Option<sqlparser::ast::Expr>
offset
&Option<sqlparser::ast::Offset>
select
Option<&sqlparser::ast::Select>