# How to read a parquet file applying a filter?

**URL:** https://discourse.julialang.org/t/how-to-read-a-parquet-file-applying-a-filter/113982
**Category:** General Usage
**Created:** [May 8, 2024, 5:39am UTC](https://discourse.julialang.org/t/how-to-read-a-parquet-file-applying-a-filter/113982 "2024-05-08T05:39:19Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![laygr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laygr/32/209082_2.png) [@laygr](https://discourse.julialang.org/u/laygr)
#### Post date: [May 8, 2024, 5:39am UTC](https://discourse.julialang.org/t/how-to-read-a-parquet-file-applying-a-filter/113982/1 "2024-05-08T05:39:19Z")

</div>

In python, we can do:

```
import pyarrow.parquet as pq
filter = ('some_column', '=', 'some_value')
pq.read_table(file_path, filters=[filter]).to_pandas()

```

How can I apply a filter similarly when reading a parquet file in Julia?

I’ve tried:

```
using Parquet
filter = row -> row.some_column == "some_value"
Parquet.read_parquet(filepath, filter=filter)

```

But I get an error saying that there is no such method:

> Closest candidates are:  
> Parquet.Table(::Any, ::Parquet.File, ::Tables.Schema; rows, batchsize, column\_generator, use\_threads) got unsupported keyword argument “filter”

But, according to the source of the [Parquet](https://github.com/JuliaIO/Parquet.jl) package, the `filter` option should be supported… it says:

> `filter`: Filter function to apply while loading only a subset of partitions from a dataset. The path to the partition is provided as a parameter.

The only thing that I’ve got working is:

```
using Parquet2

return Parquet2.Dataset(file_path) |> TableOperations.filter(r -> Tables.getcolumn(r, :some_column) == some_value) |> DataFrames.DataFrame

```

But this is much slower than the Python solution.

---

<div class="post-metadata">

### Author: ![rdavis120](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@rdavis120](https://discourse.julialang.org/u/rdavis120)
#### Post date: [May 8, 2024, 7:56am UTC](https://discourse.julialang.org/t/how-to-read-a-parquet-file-applying-a-filter/113982/2 "2024-05-08T07:56:39Z")

</div>

Maybe try something like this:

```julia
using DuckDB, DataFrames
db = DuckDB.DB()
DuckDB.query(db, "select * from '/path/*.parquet' where some_column = some_value") |> DataFrames.DataFrame

```

---

<div class="post-metadata">

### Author: ![laygr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laygr/32/209082_2.png) [@laygr](https://discourse.julialang.org/u/laygr)
#### Post date: [May 8, 2024, 6:08pm UTC](https://discourse.julialang.org/t/how-to-read-a-parquet-file-applying-a-filter/113982/4 "2024-05-08T18:08:18Z")

</div>

Yeah, there is a slight but noticeable speedup. Thanks!  
🦆 to the rescue.

Do you know how I could read in chunks using DuckDB?  
Some parquet files don’t fit in my RAM even after applying the WHERE clause.

---

<div class="post-metadata">

### Author: ![rdavis120](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@rdavis120](https://discourse.julialang.org/u/rdavis120)
#### Post date: [May 8, 2024, 6:51pm UTC](https://discourse.julialang.org/t/how-to-read-a-parquet-file-applying-a-filter/113982/5 "2024-05-08T18:51:06Z")

</div>

Yes it is supported by the duckdb library and the Julia client api. You can see an example [here](https://github.com/duckdb/duckdb/blob/d9efdd14270245c4369096e909acecea174d86cc/tools/juliapkg/test/test_stream_data_chunk.jl#L41) in tests.

The issue is that the Tables _partitions_ interface is not yet supported in the client api. If someone knew the tables partition interface well enough to contribute, it would help.

---

<div class="post-metadata">

### Author: ![laygr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laygr/32/209082_2.png) [@laygr](https://discourse.julialang.org/u/laygr)
#### Post date: [May 9, 2024, 7:12pm UTC](https://discourse.julialang.org/t/how-to-read-a-parquet-file-applying-a-filter/113982/6 "2024-05-09T19:12:59Z")

</div>

I appreciate the example, but I’m not getting the expected behavior.  
I ran the test and it blew my RAM because instead of streaming the result in chunks, it tried to return the 1000000000000 rows in a single chunk.
