[Python] libcurl error on scanning huge dataset using `polars.scan_pyarrow_dataset`
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
### Describe the bug, including details regarding any error messages, version, and platform.
xref: pola-rs/polars#9505
We have some huge datasets on S3 (filecount > 100,000), scanning with `.scanner` works well but not with `polars.scan_pyarrow_dataset`, raising the following libcurl error.
```bash
---------------------------------------------------------------------------
ComputeError Traceback (most recent call last)
Cell In[2], line 16
14 files = ds.files
15 ds = dataset(files[:300], format="parquet", filesystem=fs)
---> 16 pl.scan_pyarrow_dataset(ds).select(pl.col("area").head()).collect()
File /mnt/venvs/main/lib/python3.10/site-packages/polars/lazyframe/frame.py:1504, in LazyFrame.collect(self, type_coercion, predicate_pushdown, projection_pushdown, simplify_expression, no_optimization, slice_pushdown, common_subplan_elimination, streaming)
1493 common_subplan_elimination = False
1495 ldf = self._ldf.optimization_toggle(
1496 type_coercion,
1497 predicate_pushdown,
(...)
1502 streaming,
1503 )
-> 1504 return wrap_df(ldf.collect())
ComputeError: OSError: When reading information for key '' in bucket '': AWS Error NETWORK_CONNECTION during HeadObject operation: curlCode 43, A libcurl function was given a bad argument
```
While it is a `polars` bug, the error is raised from `pyarrow`, so I open an issue here with polars xref.
This error message above is generated using `.head()` but effectively all scanner suffer the same issue.
I just observed that the total number of files is a critical factor: when restricted to <=272 files scanning in `polars` always succeeded, for datasets with more files `polars` always fails.
Script used:
```python
import polars as pl
from pyarrow.dataset import dataset
from pyarrow.fs import S3FileSystem
fs = S3FileSystem(
access_key=access_key,
secret_key=secret_key,
region=region,
endpoint_override=endpoint_override,
)
ds = dataset("my-bucket/common-prefix", format="parquet", partitioning="hive", filesystem=fs)
ds.head(10) # succeeded in few secs
pl.scan_pyarrow_dataset(ds).select(pl.col("area").head()).collect() # failed after >10 mins with libcurl error
files = ds.files # to get the full list of URIs
ds = dataset(files[:300], format="parquet", filesystem=fs) # restrict num of files
ds.head(10) # still works
pl.scan_pyarrow_dataset(ds).select(pl.col("area").head()).collect() # failed after >10 mins with libcurl error
ds = dataset(files[:272], format="parquet", filesystem=fs)
pl.scan_pyarrow_dataset(ds).select(pl.col("area").head()).collect() # now it works
```
Version info:
```bash
--------Version info---------
Polars: 0.18.3
Index type: UInt32
Platform: # it's ubuntu jammy latest, I forgot to copy the output
Python: 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0]
----Optional dependencies----
numpy: 1.24.3
pandas: 1.5.2
pyarrow: 12.0.1
connectorx:
deltalake:
fsspec:
matplotlib:
xlsx2csv:
xlsxwriter:
```
All packages are installed via pip.
### Component(s)
Python
Contributor guide
Assessment
This issue has not been assessed yet.