Viranshul-P opened a new pull request, #41763:
URL: https://github.com/apache/beam/pull/41763
Fixes #41762.
`ReadFromParquet(..., as_rows=True)` builds its Beam schema with
`beam_schema_from_arrow_schema`, which knew only the primitive types, lists,
maps and structs. So any file with a timestamp or date column failed at
construction with `ValueError: Unrecognized arrow type`. That covers every
pandas `to_parquet` file with a datetime column. Writing has the matching gap:
`WriteToParquet` on a schema'd PCollection with a `Timestamp` or
`datetime.date` field hit the `NotImplementedError` for logical types (#23817).
Changes in `typehints/arrow_type_compatibility.py`:
- Arrow timestamp (any unit, any or no time zone) → Beam `Timestamp`
(`MicrosInstant`). A timestamp without a time zone is read as UTC, as Java's
`ArrowConversion` does (it maps ms/us timestamps to `DATETIME`).
- Arrow `date32`/`date64` → Beam `Date`.
- Beam `MicrosInstant`/`MillisInstant` → `timestamp('us', tz='UTC')`, and
`Date` → `date32`, for writing.
- `PyarrowBatchConverter` converts top-level timestamp columns to and from
`Timestamp`. The column is cast to microseconds with a safe cast, so nanosecond
values that are whole microseconds convert, and finer ones raise `ArrowInvalid`
instead of being truncated silently.
Not in this PR: decimal and time columns still raise, and `Timestamp` values
nested inside structs, lists or maps are not converted (structs are read as
dicts today, see #41100). Arrow decimals fix their precision and scale in the
type, which Beam's `Decimal` doesn't carry. Java leaves them out for the same
reason. Other logical types still raise as before (#23817).
Tests:
- `parquetio_test.py::test_schema_read_timestamp_and_date_columns` reads a
file with naive ms, `America/New_York` us, ns (pandas default) and date32
columns, nulls included.
- `parquetio_test.py::test_schema_read_write_timestamp_and_date` covers the
round trip through `WriteToParquet` and `ReadFromParquet(as_rows=True)`.
- A new `ArrowBatchConverterTest` case with `Timestamp` and `date` fields.
All three fail on master and pass with this change. `typehints/` and
`io/parquetio_test.py` pass (1472 passed, Windows 11, Python 3.12;
`test_sink_transform*` is deselected because it hangs on Windows on master
too), and so does `yaml/yaml_io_test.py`. yapf 0.43.0 and ruff 0.15.7 report
nothing.
This change was written with help from Claude Code; the commit carries a
`Generated-by` trailer.
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
`addresses #123` or `fixes #456`).
- [x] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
🤖 Generated with [Claude Code](https://claude.com/claude-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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]