Repository navigation
Read UNLOAD timestamps at microseconds #1233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8f98061
5d1284d
7633e22
b9287d7
7871a6c
4552f58
b71c657
9c0b3f2
b08940f
bc55d4b
043e295
1dc9b28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,11 @@ This cursor downloads the CSV file after executing the query and loads it into a | |
| Performance is better than fetching data with Cursor. | ||
|
|
||
| PolarsCursor uses [Polars](https://pola.rs/) native reading capabilities (`pl.read_csv`, `pl.read_parquet`) and | ||
| does not require PyArrow as a dependency. CSV results read without the chunksize option, and | ||
| UNLOAD results read with it when pyarrow is installed and `execute()` is given no Polars read | ||
| options, use PyAthena's own S3FileSystem (fsspec compatible), and other reads use Polars' native | ||
| S3 access, so s3fs is also not required. | ||
| does not require PyArrow as a dependency; for UNLOAD results with timestamps read with Polars 1.x, see {ref}`polars-unload-options`. | ||
| CSV results read without the chunksize option, UNLOAD results read with it when pyarrow is | ||
| installed and `execute()` is given no Polars read options, and UNLOAD results with timestamps read | ||
| without it with Polars 1.x use PyAthena's own S3FileSystem (fsspec compatible), and other reads use | ||
| Polars' native S3 access, so s3fs is also not required. | ||
|
|
||
| Options passed to `execute()`, other than PolarsCursor's own options such as `chunksize`, are passed to the Polars read function. | ||
| Column types for a CSV result are given as `schema_overrides`, which replaces PyAthena's column types. | ||
|
|
@@ -214,12 +215,22 @@ cursor = connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/", | |
| If the unload option is enabled, the Parquet file itself has a schema, so the conversion is done to the dtypes according to that schema, | ||
| and the `types` setting of the Converter class is not used. | ||
|
|
||
| (polars-unload-options)= | ||
|
|
||
| ### Unload Options | ||
|
|
||
| PolarsCursor supports the unload option, as does {ref}`arrow-cursor`. | ||
|
|
||
| See {ref}`arrow-unload-options` for more information. | ||
|
|
||
| Timestamps of UNLOAD results are read at microseconds, as `Datetime("us")`. | ||
| Polars 2.0 and later read them with Polars. | ||
| Polars 1.x reads them correctly only through pyarrow: | ||
|
|
||
| - Without the chunksize option and without Polars read options given to `execute()`, a result with timestamps is read with pyarrow when it is installed, through PyAthena's S3FileSystem, and a warning is logged. | ||
| - With the chunksize option and without Polars read options, the chunks are read with pyarrow when it is installed. | ||
| - Otherwise Polars 1.x reads the timestamps at nanoseconds, which gives wrong values outside 1677-09-21 to 2262-04-11; they are cast to microseconds, and a warning is logged. | ||
|
|
||
| The unload option can be enabled by specifying it in the `cursor_kwargs` argument of the connect method or as an argument to the cursor method. | ||
| An argument to the cursor method takes precedence over the same key in `cursor_kwargs`. | ||
|
|
||
|
|
@@ -394,7 +405,7 @@ cursor = connect(s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/", | |
| df = cursor.execute("SELECT * FROM many_rows").as_polars() | ||
| ``` | ||
|
|
||
| They apply to the reads through PyAthena's filesystem: CSV results read without the chunksize option, which use `"bytes"` and 5 MiB blocks by default, and the Parquet files of UNLOAD results read with the chunksize option when pyarrow is installed and `execute()` is given no Polars read options. | ||
| They apply to the reads through PyAthena's filesystem: CSV results read without the chunksize option and, with Polars 1.x, the Parquet files of UNLOAD results with timestamps read without it, which use `"bytes"` and 5 MiB blocks by default, and the Parquet files of UNLOAD results read with the chunksize option when pyarrow is installed and `execute()` is given no Polars read options. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Round 2 finding (repaired in 5e4fac3): the Polars 1.x fallback reads the data manifest through |
||
| Of the latter, a file of up to 32 MiB is read at once, and a larger one is read with the given `cache_type`, or without it with the `"none"` cache, which requests only the ranges that pyarrow reads. | ||
| With `storage_options` given to `execute()`, the given options replace PyAthena's S3 settings, and `block_size` and `cache_type` do not apply. | ||
| For a CSV result read without the chunksize option, the options are passed to `fsspec.open()`, which uses PyAthena's S3FileSystem; for the other reads, they are passed to the Polars read function, which uses its native S3 access by default and fsspec with `use_pyarrow=True`. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review round 2 (claims, existing callers, operators, docs readers, evidence). Base 9e2bf6e (after the rebase onto #1226), head 5e4fac3.
Claims re-checked against evidence:
ARROW:schema: two live UNLOADs; the committed fixture is the second.schemacannot be combined withuse_pyarrow=True: measured on Polars 1.39.0, 1.44.2, and 2.0.0.int96_options()on Polars main has noMapcase.rechunkrepair, 3 alternating runs; the PR table is updated.FINDINGS, repaired in 5e4fac3 and the PR body:
polars.mdstatements outside the diff, which list the reads that use PyAthena's S3FileSystem, omitted the Polars 1.x fallback (see the thread below).storage_optionsalone triggersNotSupportedErroron Polars 1.x with timestamps, or that the private Polars reader signatures change.Deferred: at the minimum versions, 5
test_read_csv_with_pyarrow_matches_pandascases fail identically on master 9e2bf6e (CSV path, pre-existing, outside this change).Not measured: S3-backed timing and request counts of the Polars 1.x fallback, which goes through PyAthena's S3FileSystem and its retries instead of object_store.