MCPcopy Create free account
hub / github.com/apache/datafusion / max_rows

Method max_rows

datafusion/expr/src/logical_plan/plan.rs:1310–1396  ·  view source on GitHub ↗

Returns the maximum number of rows that this plan can output, if known. If `None`, the plan can return any number of rows. If `Some(n)` then the plan can return at most `n` rows but may return fewer.

(self: &LogicalPlan)

Source from the content-addressed store, hash-verified

1308 /// If `None`, the plan can return any number of rows.
1309 /// If `Some(n)` then the plan can return at most `n` rows but may return fewer.
1310 pub fn max_rows(self: &LogicalPlan) -> Option<usize> {
1311 match self {
1312 LogicalPlan::Projection(Projection { input, .. }) => input.max_rows(),
1313 LogicalPlan::Filter(filter) => {
1314 if filter.is_scalar() {
1315 Some(1)
1316 } else {
1317 filter.input.max_rows()
1318 }
1319 }
1320 LogicalPlan::Window(Window { input, .. }) => input.max_rows(),
1321 LogicalPlan::Aggregate(Aggregate {
1322 input, group_expr, ..
1323 }) => {
1324 // Empty group_expr will return Some(1)
1325 if group_expr
1326 .iter()
1327 .all(|expr| matches!(expr, Expr::Literal(_, _)))
1328 {
1329 Some(1)
1330 } else {
1331 input.max_rows()
1332 }
1333 }
1334 LogicalPlan::Sort(Sort { input, fetch, .. }) => {
1335 match (fetch, input.max_rows()) {
1336 (Some(fetch_limit), Some(input_max)) => {
1337 Some(input_max.min(*fetch_limit))
1338 }
1339 (Some(fetch_limit), None) => Some(*fetch_limit),
1340 (None, Some(input_max)) => Some(input_max),
1341 (None, None) => None,
1342 }
1343 }
1344 LogicalPlan::Join(Join {
1345 left,
1346 right,
1347 join_type,
1348 ..
1349 }) => match join_type {
1350 JoinType::Inner => Some(left.max_rows()? * right.max_rows()?),
1351 JoinType::Left | JoinType::Right | JoinType::Full => {
1352 match (left.max_rows()?, right.max_rows()?, join_type) {
1353 (0, 0, _) => Some(0),
1354 (max_rows, 0, JoinType::Left | JoinType::Full) => Some(max_rows),
1355 (0, max_rows, JoinType::Right | JoinType::Full) => Some(max_rows),
1356 (left_max, right_max, _) => Some(left_max * right_max),
1357 }
1358 }
1359 JoinType::LeftSemi | JoinType::LeftAnti | JoinType::LeftMark => {
1360 left.max_rows()
1361 }
1362 JoinType::RightSemi | JoinType::RightAnti | JoinType::RightMark => {
1363 right.max_rows()
1364 }
1365 },
1366 LogicalPlan::Repartition(Repartition { input, .. }) => input.max_rows(),
1367 LogicalPlan::Union(Union { inputs, .. }) => {

Callers 1

check_subquery_exprFunction · 0.80

Calls 6

is_scalarMethod · 0.80
allMethod · 0.80
get_fetch_typeMethod · 0.80
iterMethod · 0.45
minMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected