Skip to content

Commit

Permalink
Fix filter pushdown (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrebnov authored Aug 2, 2024
1 parent 15fa005 commit c49db80
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sql/sql_provider_datafusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,14 @@ impl<T, P> SqlExec<T, P> {
let filter_expr = self
.filters
.iter()
.map(|f| expr::to_sql_with_engine(f, self.engine))
.map(|f| match f {
// DataFusion optimization uses aliases to preserve original expression names during optimizations and type coercions:
// https://github.com/apache/datafusion/issues/3794
// If there is a filter with additional alias information, we must use the expression only
// as original expression name is unnecessary and the alias can't be part of the WHERE clause
Expr::Alias(alias) => expr::to_sql_with_engine(&alias.expr, self.engine),
_ => expr::to_sql_with_engine(f, self.engine),
})
.collect::<expr::Result<Vec<_>>>()
.context(UnableToGenerateSQLSnafu)?;
format!("WHERE {}", filter_expr.join(" AND "))
Expand Down

0 comments on commit c49db80

Please sign in to comment.