adriangb commented on code in PR #13795:
URL: https://github.com/apache/datafusion/pull/13795#discussion_r1888501429
##########
datafusion/physical-optimizer/src/pruning.rs:
##########
@@ -2052,6 +2052,109 @@ mod tests {
}
}
+ #[test]
+ fn prune_all_rows_null_counts() {
+ // if null_count = row_count then we should prune the container for i
= 0
+ // regardless of the statistics
+ let schema = Arc::new(Schema::new(vec![Field::new("i",
DataType::Int32, true)]));
+ let statistics = TestStatistics::new().with(
+ "i",
+ ContainerStats::new_i32(
+ vec![Some(0)], // min
+ vec![Some(0)], // max
+ )
+ .with_null_counts(vec![Some(1)])
+ .with_row_counts(vec![Some(1)]),
+ );
+ let expected_ret = &[false];
+ prune_with_expr(col("i").eq(lit(0)), &schema, &statistics,
expected_ret);
+
+ // this should be true even if the container stats are missing
+ let schema = Arc::new(Schema::new(vec![Field::new("i",
DataType::Int32, true)]));
+ let container_stats = ContainerStats {
+ min: Some(Arc::new(Int32Array::from(vec![None]))),
+ max: Some(Arc::new(Int32Array::from(vec![None]))),
+ null_counts: Some(Arc::new(UInt64Array::from(vec![Some(1)]))),
+ row_counts: Some(Arc::new(UInt64Array::from(vec![Some(1)]))),
+ ..ContainerStats::default()
+ };
+ let statistics = TestStatistics::new().with("i", container_stats);
+ let expected_ret = &[false];
+ prune_with_expr(col("i").eq(lit(0)), &schema, &statistics,
expected_ret);
+
+ // If the null counts themselves are missing we should be able to fall
back to the stats
+ let schema = Arc::new(Schema::new(vec![Field::new("i",
DataType::Int32, true)]));
+ let container_stats = ContainerStats {
+ min: Some(Arc::new(Int32Array::from(vec![Some(0)]))),
+ max: Some(Arc::new(Int32Array::from(vec![Some(0)]))),
+ null_counts: Some(Arc::new(UInt64Array::from(vec![None]))),
+ row_counts: Some(Arc::new(UInt64Array::from(vec![Some(1)]))),
+ ..ContainerStats::default()
+ };
+ let statistics = TestStatistics::new().with("i", container_stats);
+ let expected_ret = &[true];
+ prune_with_expr(col("i").eq(lit(0)), &schema, &statistics,
expected_ret);
+ let expected_ret = &[false];
+ prune_with_expr(col("i").gt(lit(0)), &schema, &statistics,
expected_ret);
+
+ // Same for the row counts
+ let schema = Arc::new(Schema::new(vec![Field::new("i",
DataType::Int32, true)]));
+ let container_stats = ContainerStats {
+ min: Some(Arc::new(Int32Array::from(vec![Some(0)]))),
+ max: Some(Arc::new(Int32Array::from(vec![Some(0)]))),
+ null_counts: Some(Arc::new(UInt64Array::from(vec![Some(1)]))),
+ row_counts: Some(Arc::new(UInt64Array::from(vec![None]))),
+ ..ContainerStats::default()
+ };
+ let statistics = TestStatistics::new().with("i", container_stats);
+ let expected_ret = &[true];
+ prune_with_expr(col("i").eq(lit(0)), &schema, &statistics,
expected_ret);
+ let expected_ret = &[false];
+ prune_with_expr(col("i").gt(lit(0)), &schema, &statistics,
expected_ret);
Review Comment:
@alamb see test case here for
https://github.com/apache/datafusion/pull/13795#issuecomment-2548414526
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]