2010YOUY01 commented on code in PR #61: URL: https://github.com/apache/datafusion-site/pull/61#discussion_r2009041940
########## content/blog/2025-03-21-parquet-pushdown.md: ########## @@ -0,0 +1,312 @@ +--- +layout: post +title: Efficient Filter Pushdown in Parquet +date: 2025-03-21 +author: Xiangpeng Hao +categories: [performance] +--- + +<style> +figure { + margin: 20px 0; +} + +figure img { + display: block; + max-width: 80%; +} + +figcaption { + font-style: italic; + margin-top: 10px; + color: #555; + font-size: 0.9em; + max-width: 80%; +} +</style> + +<!-- +{% comment %} +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to you under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{% endcomment %} +--> + +_Editor's Note: This blog was first published on [Xiangpeng Hao's blog]. Thanks to [InfluxData] for sponsoring this work as part of his PhD funding._ + +[Xiangpeng Hao's blog]: https://blog.xiangpeng.systems/posts/parquet-pushdown/ +[InfluxData]: https://www.influxdata.com/ +<hr/> + + +In the [previous post], we discussed how [Apache DataFusion] prunes [Apache Parquet] files to skip irrelevant **files/row_groups** (sometimes also [pages](https://parquet.apache.org/docs/file-format/pageindex/)). + +This post discusses how Parquet readers skip irrelevant **rows** while scanning data, +leveraging Parquet's columnar layout by first reading only filter columns, +and then selectively reading other columns only for matching rows. + + +[previous post]: https://datafusion.apache.org/blog/2025/03/20/parquet-pruning +[Apache DataFusion]: https://datafusion.apache.org/ +[Apache Parquet]: https://parquet.apache.org/ + +## Why filter pushdown in Parquet? + +Below is an example query that reads sensor data with filters on `date_time` and `location`. +Without filter pushdown, all rows from location, val, and date_time columns are decoded before `location='office'` is evaluated. Filter pushdown is especially useful when the filter is selective, i.e., removes many rows. Review Comment: ```suggestion Without filter pushdown, all rows from `location`, `val`, and `date_time` columns are decoded before `location='office'` is evaluated. Filter pushdown is especially useful when the filter is selective, i.e., removes many rows. ``` ########## content/blog/2025-03-21-parquet-pushdown.md: ########## @@ -0,0 +1,312 @@ +--- +layout: post +title: Efficient Filter Pushdown in Parquet +date: 2025-03-21 +author: Xiangpeng Hao +categories: [performance] +--- + +<style> +figure { + margin: 20px 0; +} + +figure img { + display: block; + max-width: 80%; +} + +figcaption { + font-style: italic; + margin-top: 10px; + color: #555; + font-size: 0.9em; + max-width: 80%; +} +</style> + +<!-- +{% comment %} +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to you under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{% endcomment %} +--> + +_Editor's Note: This blog was first published on [Xiangpeng Hao's blog]. Thanks to [InfluxData] for sponsoring this work as part of his PhD funding._ + +[Xiangpeng Hao's blog]: https://blog.xiangpeng.systems/posts/parquet-pushdown/ +[InfluxData]: https://www.influxdata.com/ +<hr/> + + +In the [previous post], we discussed how [Apache DataFusion] prunes [Apache Parquet] files to skip irrelevant **files/row_groups** (sometimes also [pages](https://parquet.apache.org/docs/file-format/pageindex/)). + +This post discusses how Parquet readers skip irrelevant **rows** while scanning data, +leveraging Parquet's columnar layout by first reading only filter columns, +and then selectively reading other columns only for matching rows. + + +[previous post]: https://datafusion.apache.org/blog/2025/03/20/parquet-pruning +[Apache DataFusion]: https://datafusion.apache.org/ +[Apache Parquet]: https://parquet.apache.org/ + +## Why filter pushdown in Parquet? + +Below is an example query that reads sensor data with filters on `date_time` and `location`. +Without filter pushdown, all rows from location, val, and date_time columns are decoded before `location='office'` is evaluated. Filter pushdown is especially useful when the filter is selective, i.e., removes many rows. + + +```sql +SELECT val, location +FROM sensor_data +WHERE date_time > '2025-03-11' AND location = 'office'; +``` + +<figure> + <img src="/blog/images/parquet-pushdown/pushdown-vs-no-pushdown.jpg" alt="Parquet pruning skips irrelevant files/row_groups, while filter pushdown skips irrelevant rows. Without filter pushdown, all rows from location, val, and date_time columns are decoded before `location='office'` is evaluated. Filter pushdown is especially useful when the filter is selective, i.e., removes many rows." width="80%" class="img-responsive"> + <figcaption> + Parquet pruning skips irrelevant files/row_groups, while filter pushdown skips irrelevant rows. Without filter pushdown, all rows from location, val, and date_time columns are decoded before `location='office'` is evaluated. Filter pushdown is especially useful when the filter is selective, i.e., removes many rows. + </figcaption> +</figure> + + +In our setup, sensor data is aggregated by date — each day has its own Parquet file. +At planning time, DataFusion prunes the unneeded Parquet files, i.e., `2025-03-10.parquet` and `2025-03-11.parquet`. + +Once the files to read are located, the [*DataFusion's current default implementation*](https://github.com/apache/datafusion/issues/3463) reads all the projected columns (`sensor_id`, `val`, and `location`) into Arrow RecordBatches, then applies the filters over `location` to get the final set of rows. + +A better approach is called **filter pushdown**, which evaluates filter conditions first and only decodes data that passes these conditions. Review Comment: ```suggestion A better approach is called **filter pushdown** with **late materialization**, which evaluates filter conditions first and only decodes data that passes these conditions. ``` -- 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-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org