You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "adriangb (via GitHub)" <gi...@apache.org> on 2026/08/05 16:46:03 UTC
[I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
adriangb opened a new issue, #24109:
URL: https://github.com/apache/datafusion/issues/24109
### Describe the bug
With `datafusion.execution.parquet.pushdown_filters = true`, a predicate on a struct field is reported as fully handled by the scan — so `FilterExec` is removed from the plan — and then never applied. The query returns **every row**.
The trigger is not `get_field` itself; it is the expression adapter interposing a cast on the struct column, which happens whenever the table's declared schema differs from the file's physical schema for that column.
### To Reproduce
```sql
-- file written with: id Int64, s Struct<x Int64, y Utf8>, v Int64, three rows, x = 100/200/300
CREATE EXTERNAL TABLE fullt (id INT, s STRUCT<x INT, y VARCHAR>, v INT)
STORED AS PARQUET LOCATION '.../w.parquet';
set datafusion.execution.parquet.pushdown_filters = true;
SELECT id FROM fullt WHERE v = 20; -- correct: 1 row
SELECT id FROM fullt WHERE s['x'] = 200; -- WRONG: 3 rows
```
The same query against a table whose schema is *inferred* from the file — so no cast is inserted — filters correctly. Here the declared `INT` differs from the file's `Int64`, and `VARCHAR` maps to `Utf8View` against the file's `Utf8`, so a cast is inserted.
`EXPLAIN` for the broken case shows no `FilterExec` anywhere; the scan has claimed the predicate:
```
logical_plan
01)Projection: fullt.id
02)--Filter: __datafusion_extracted_1 = Int32(200)
03)----Projection: get_field(fullt.s, Utf8("x")) AS __datafusion_extracted_1, fullt.id
04)------TableScan: fullt projection=[id, s], partial_filters=[get_field(fullt.s, Utf8("x")) = Int32(200)]
physical_plan DataSourceExec: ... projection=[id, s], predicate=get_field(s@1, x) = 200
```
### Expected behavior
One row. A predicate the scan reports as exactly handled must actually be applied.
### Mechanism
1. `ParquetSource::try_pushdown_filters` (`datasource-parquet/src/source.rs`) decides exactness with `can_expr_be_pushed_down_with_schemas(&filter, pushable_schema)`, where `pushable_schema` is the **table** schema. Against it the predicate is `get_field(Column("s"), 'x') = 200`, which `PushdownChecker` accepts, so the filter is marked `PushedDown::Yes` and `FilterExec` is removed.
2. At file-open time the physical expression adapter rewrites the predicate against the **physical file** schema, producing `get_field(CAST(s AS Struct{x: Int32, y: Utf8View}), 'x') = 200`.
3. `PushdownChecker::f_down` only recognises `get_field` whose first argument is a bare `Column`. Here it is a `CastExpr`, so the visitor descends past it, reaches `Column("s")`, sees a `Struct`, sets `non_primitive_columns = true`, and `pushdown_columns` returns `None`.
4. `build_row_filter` collects no candidate for that conjunct and returns `Ok(None)`. The conjunct is dropped, and nothing downstream re-applies it — step 1 already removed `FilterExec`.
### This is an instance of a general category
The specific `get_field`-over-a-cast case is easy enough to patch, but the shape of the bug will recur: **a static determination made at planning time about what the scan can do, and the runtime construction that has to make good on it, are computed by different code against different schemas, and there is no mechanism forcing them to agree.** Planning decides against the table schema; the row filter is built per file against that file's physical schema after adaptation. Any divergence between the two turns a "predicate handled exactly" promise into a silently dropped predicate.
The codebase already knows this hazard exists and patches it case by case — `validate_predicate_does_not_reference_virtual_columns` in `opener/mod.rs` exists for exactly this reason, and its doc comment says "Silently dropping such a predicate would produce wrong results." That is one instance guarded by hand; this is another; there are likely more, and each new pushdown-eligible expression shape is a chance to add one.
The structural fix is to remove the cliff: **let `ParquetOpener` apply a predicate as an ordinary post-decode filter when it cannot be turned into a row filter.** Then failing to build a row filter — for any reason, known or not yet discovered — costs at most some performance instead of correctness, and the planner's "exactly handled" claim stays true regardless of what the per-file construction manages to do. Individual cases can then be optimised into row filters as they are understood, rather than each unhandled case being a latent wrong-results bug.
### Additional context
Found while reviewing apache/datafusion#24090 (nested projection pruning for Parquet). That PR does not cause this — `row_filter.rs` is untouched by it and the failing query takes an unchanged code path — but it is worth flagging alongside it, because a table whose declared nested schema is narrower than the file's *always* carries the adapter cast that triggers this. So on exactly the tables that feature targets, any `WHERE s['field'] = ...` with `pushdown_filters = true` is wrong today.
It is also why nested pruning cannot simply be extended to the filter path as-is: filter pushdown over a narrowed nested column is currently unsound, not merely unoptimised. Teaching `PushdownChecker` to look through the cast would address both, but only if the fallback above exists to catch whatever it still misses.
cc @alamb
---
_Generated by [Claude Code](https://claude.ai/code)_
--
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: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on issue #24109:
URL: https://github.com/apache/datafusion/issues/24109#issuecomment-5195458992
@alamb I think you need the `CREATE EXTERNAL TABLE` step. I updated the repro:
```
❯ datafusion-cli
DataFusion CLI v54.0.0
> COPY (SELECT column1 AS id, column2 AS s, column3 AS v
FROM VALUES (1, {'x': 100, 'y': 'foo'}, 10),
(2, {'x': 200, 'y': 'foo'}, 20),
(3, {'x': 300, 'y': 'foo'}, 30))
TO '/tmp/foo.parquet' STORED AS PARQUET;
+-------+
| count |
+-------+
| 3 |
+-------+
1 row(s) fetched.
Elapsed 0.003 seconds.
>
CREATE EXTERNAL TABLE fullt (id INT, s STRUCT<x INT, y VARCHAR>, v INT)
STORED AS PARQUET LOCATION '/tmp/foo.parquet';
0 row(s) fetched.
Elapsed 0.001 seconds.
> SET datafusion.execution.parquet.pushdown_filters = true;
0 row(s) fetched.
Elapsed 0.000 seconds.
> SELECT id FROM fullt WHERE v = 20;
+----+
| id |
+----+
| 2 |
+----+
1 row(s) fetched.
Elapsed 0.003 seconds.
> SELECT id FROM fullt WHERE s['x'] = 200;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
+----+
3 row(s) fetched.
Elapsed 0.001 seconds.
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #24109:
URL: https://github.com/apache/datafusion/issues/24109#issuecomment-5195255051
I couldn't reproduce this
For me this came back with 1 row as expected
> SELECT id FROM fullt WHERE s['x'] = 200; -- WRONG: 3 rows
```sql
> copy (select column1 as id, column2 as s from values (1, {'x': 100, 'y': 'foo'}), (2, {'x': 200, 'y': 'foo'}),(3, {'x': 300, 'y': 'foo'}) as s ) to '/tmp/foo.parquet';
+-------+
| count |
+-------+
| 3 |
+-------+
1 row(s) fetched.
Elapsed 0.006 seconds.
> select * from '/tmp/foo.parquet';
+----+------------------+
| id | s |
+----+------------------+
| 1 | {x: 100, y: foo} |
| 2 | {x: 200, y: foo} |
| 3 | {x: 300, y: foo} |
+----+------------------+
3 row(s) fetched.
Elapsed 0.004 seconds.
> set datafusion.execution.parquet.pushdown_filters = true;
0 row(s) fetched.
Elapsed 0.001 seconds.
> set datafusion.execution.parquet.pushdown_filters = true;
^C
> SELECT id FROM '/tmp/foo.parquet' WHERE id = 1;
+----+
| id |
+----+
| 1 |
+----+
1 row(s) fetched.
Elapsed 0.010 seconds.
> SELECT id FROM '/tmp/foo.parquet' WHERE s['x'] = 200;
+----+
| id |
+----+
| 2 |
+----+
1 row(s) fetched.
Elapsed 0.004 seconds.
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #24109:
URL: https://github.com/apache/datafusion/issues/24109#issuecomment-5195716036
I added this as something to fix for 55
- https://github.com/apache/datafusion/issues/22393
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #24109:
URL: https://github.com/apache/datafusion/issues/24109#issuecomment-5245016665
I tried this on DataFusion 54.0.0 and I still got the same (incorrect) answers -- so it doesn't seem to be a regression introduced in 54.
I got the correct answer using 53.0.0, so this seems to be a regression introduced in 54
```sql
andrewlamb@Andrews-MacBook-Pro-3:~/Downloads$ ~/Software/datafusion-cli/datafusion-cli-53.1.0
DataFusion CLI v53.1.0
> COPY (SELECT column1 AS id, column2 AS s, column3 AS v
FROM VALUES (1, {'x': 100, 'y': 'foo'}, 10),
(2, {'x': 200, 'y': 'foo'}, 20),
(3, {'x': 300, 'y': 'foo'}, 30))
TO '/tmp/foo.parquet' STORED AS PARQUET;
+-------+
| count |
+-------+
| 3 |
+-------+
1 row(s) fetched.
Elapsed 0.007 seconds.
> CREATE EXTERNAL TABLE fullt (id INT, s STRUCT<x INT, y VARCHAR>, v INT)
STORED AS PARQUET LOCATION '/tmp/foo.parquet';
0 row(s) fetched.
Elapsed 0.002 seconds.
> SET datafusion.execution.parquet.pushdown_filters = true;
0 row(s) fetched.
Elapsed 0.000 seconds.
> SELECT id FROM fullt WHERE v = 20;
+----+
| id |
+----+
| 2 |
+----+
1 row(s) fetched.
Elapsed 0.003 seconds.
> SELECT id FROM fullt WHERE s['x'] = 200;
+----+
| id |
+----+
| 2 |
+----+
1 row(s) fetched.
Elapsed 0.002 seconds.
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #24109:
URL: https://github.com/apache/datafusion/issues/24109#issuecomment-5195256896
I will try on latest main
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #24109:
URL: https://github.com/apache/datafusion/issues/24109#issuecomment-5195713094
Yes, I got it now
```sql
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
+----+
3 row(s) fetched.
Elapsed 0.000 seconds.
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results) [datafusion]
Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb closed issue #24109: Parquet filter pushdown silently drops a `get_field` predicate when the file needs schema adaptation (wrong results)
URL: https://github.com/apache/datafusion/issues/24109
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org