Wrap a plan in a limit
(
&self,
input: LogicalPlan,
limit_clause: Option<LimitClause>,
planner_context: &mut PlannerContext,
)
| 245 | |
| 246 | /// Wrap a plan in a limit |
| 247 | fn limit( |
| 248 | &self, |
| 249 | input: LogicalPlan, |
| 250 | limit_clause: Option<LimitClause>, |
| 251 | planner_context: &mut PlannerContext, |
| 252 | ) -> Result<LogicalPlan> { |
| 253 | let Some(limit_clause) = limit_clause else { |
| 254 | return Ok(input); |
| 255 | }; |
| 256 | |
| 257 | let empty_schema = DFSchema::empty(); |
| 258 | |
| 259 | let (skip, fetch, limit_by_exprs) = match limit_clause { |
| 260 | LimitClause::LimitOffset { |
| 261 | limit, |
| 262 | offset, |
| 263 | limit_by, |
| 264 | } => { |
| 265 | let skip = offset |
| 266 | .map(|o| self.sql_to_expr(o.value, &empty_schema, planner_context)) |
| 267 | .transpose()?; |
| 268 | |
| 269 | let fetch = limit |
| 270 | .map(|e| self.sql_to_expr(e, &empty_schema, planner_context)) |
| 271 | .transpose()?; |
| 272 | |
| 273 | let limit_by_exprs = limit_by |
| 274 | .into_iter() |
| 275 | .map(|e| self.sql_to_expr(e, &empty_schema, planner_context)) |
| 276 | .collect::<Result<Vec<_>>>()?; |
| 277 | |
| 278 | (skip, fetch, limit_by_exprs) |
| 279 | } |
| 280 | LimitClause::OffsetCommaLimit { offset, limit } => { |
| 281 | let skip = |
| 282 | Some(self.sql_to_expr(offset, &empty_schema, planner_context)?); |
| 283 | let fetch = |
| 284 | Some(self.sql_to_expr(limit, &empty_schema, planner_context)?); |
| 285 | (skip, fetch, vec![]) |
| 286 | } |
| 287 | }; |
| 288 | |
| 289 | if !limit_by_exprs.is_empty() { |
| 290 | return not_impl_err!("LIMIT BY clause is not supported yet"); |
| 291 | } |
| 292 | |
| 293 | if skip.is_none() && fetch.is_none() { |
| 294 | return Ok(input); |
| 295 | } |
| 296 | |
| 297 | LogicalPlanBuilder::from(input) |
| 298 | .limit_by_expr(skip, fetch)? |
| 299 | .build() |
| 300 | } |
| 301 | |
| 302 | /// Wrap the logical in a sort |
| 303 | pub(super) fn order_by( |
no test coverage detected