Skip to content

Commit

Permalink
Fix panic in filter predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jul 28, 2023
1 parent 350d4ca commit 2ede4d7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
10 changes: 3 additions & 7 deletions datafusion/core/src/physical_plan/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ use datafusion_common::{DataFusionError, Result};
use datafusion_execution::TaskContext;
use datafusion_expr::Operator;
use datafusion_physical_expr::expressions::BinaryExpr;
use datafusion_physical_expr::intervals::is_operator_supported;
use datafusion_physical_expr::utils::collect_columns;
use datafusion_physical_expr::intervals::check_support;
use datafusion_physical_expr::{
analyze, split_conjunction, AnalysisContext, ExprBoundaries,
OrderingEquivalenceProperties, PhysicalExpr,
Expand Down Expand Up @@ -191,11 +190,8 @@ impl ExecutionPlan for FilterExec {
fn statistics(&self) -> Statistics {
let predicate = self.predicate();

if let Some(binary) = predicate.as_any().downcast_ref::<BinaryExpr>() {
let columns = collect_columns(predicate);
if !is_operator_supported(binary.op()) || columns.is_empty() {
return Statistics::default();
}
if !check_support(predicate) {
return Statistics::default();
}

let input_stats = self.input.statistics();
Expand Down
39 changes: 39 additions & 0 deletions datafusion/core/tests/sqllogictests/test_files/predicates.slt
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,42 @@ drop table alltypes_plain;

statement ok
DROP TABLE test;

#########
# Predicates on memory tables / statistics generation
# Reproducer for https://github.com/apache/arrow-datafusion/issues/7125
#########

statement ok
CREATE TABLE t (i integer, s string, b boolean) AS VALUES
(1, 'One', true),
(2, 'Two', false),
(NULL, NULL, NULL),
(4, 'Four', false)
;

query ITB
select * from t where (b OR b) = b;
----
1 One true
2 Two false
4 Four false

query ITB
select * from t where (s LIKE 'T%') = true;
----
2 Two false

query ITB
select * from t where (i & 3) = 1;
----
1 One true




########
# Clean up after the test
########
statement ok
DROP TABLE t;

0 comments on commit 2ede4d7

Please sign in to comment.