github-actions[bot] commented on code in PR #41763:
URL: https://github.com/apache/beam/pull/41763#discussion_r4757500973
##########
sdks/python/apache_beam/typehints/arrow_type_compatibility.py:
##########
@@ -283,9 +294,15 @@ def _arrow_type_from_beam_fieldtype(
# added at field-level metadata.
output_arrow_type = pa.struct(
[_arrow_field_from_beam_field(field) for field in schema.fields])
+ elif type_info == "logical_type" and beam_fieldtype.logical_type.urn in (
+ MicrosInstant.urn(), MillisInstant.urn()):
+ output_arrow_type = _ARROW_TIMESTAMP
Review Comment:
**🟡 Medium**: `_arrow_type_from_beam_fieldtype` is also called by
`PyarrowArrayBatchConverter.__init__` (line 403) when creating a `pa.Array`
batch converter for a single element type
(`BatchConverter.from_typehints(element_type=Timestamp, batch_type=pa.Array)`
or `Optional[Timestamp]`).
Now that `_arrow_type_from_beam_fieldtype` returns `_ARROW_TIMESTAMP`
instead of raising `NotImplementedError` for `MicrosInstant` / `MillisInstant`,
`PyarrowArrayBatchConverter` construction succeeds for `Timestamp`, but its
`produce_batch` (line 413) and `explode_batch` (lines 415–418) methods do not
apply the `Timestamp` ↔ Arrow timestamp conversions:
- `produce_batch` passes `Timestamp` instances directly to
`pa.array(list(elements), type=self._arrow_type)`, which fails with
`pyarrow.lib.ArrowInvalid` because PyArrow does not recognize
`apache_beam.utils.timestamp.Timestamp`.
- `explode_batch` yields `val.as_py()`, which returns `datetime.datetime`
objects instead of `Timestamp` instances.
Consider updating `PyarrowArrayBatchConverter.produce_batch` and
`explode_batch` (lines 412–418) to convert `Timestamp` elements via `.micros`
and `_timestamps_from_arrow(batch)` when
`pa.types.is_timestamp(self._arrow_type)` / `pa.types.is_timestamp(batch.type)`.
--
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]