Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion datafusion/physical-plan/src/coalesce_partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ impl ExecutionPlan for CoalescePartitionsExec {
}

fn cardinality_effect(&self) -> CardinalityEffect {
CardinalityEffect::Equal
if self.fetch.is_none() {
CardinalityEffect::Equal
} else {
CardinalityEffect::LowerEqual
}
}

/// Tries to swap `projection` with its input, which is known to be a
Expand Down Expand Up @@ -698,4 +702,21 @@ mod tests {

Ok(())
}

#[test]
fn test_cardinality_effect_with_fetch() {
let input = test::scan_partitioned(4);

let coalesce = CoalescePartitionsExec::new(Arc::clone(&input));
assert!(matches!(
coalesce.cardinality_effect(),
CardinalityEffect::Equal
));

let coalesce = CoalescePartitionsExec::new(input).with_fetch(Some(10));
assert!(matches!(
coalesce.cardinality_effect(),
CardinalityEffect::LowerEqual
));
}
}
16 changes: 16 additions & 0 deletions datafusion/physical-plan/src/operator_statistics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,22 @@ mod tests {
Ok(())
}

#[test]
fn test_passthrough_skips_coalesce_partitions_with_fetch() -> Result<()> {
use crate::coalesce_partitions::CoalescePartitionsExec;

let registry = StatisticsRegistry::with_providers(vec![Arc::new(
PassthroughStatisticsProvider,
)]);
let source = make_source(1000);
let coalesce: Arc<dyn ExecutionPlan> =
Arc::new(CoalescePartitionsExec::new(source).with_fetch(Some(10)));

let stats = compute(&registry, coalesce.as_ref())?;
assert_eq!(stats.base.num_rows, Precision::Exact(10));
Ok(())
}

#[test]
fn test_chain_priority() -> Result<()> {
let mut registry = StatisticsRegistry::new();
Expand Down
Loading