damccorm commented on code in PR #41320:
URL: https://github.com/apache/beam/pull/41320#discussion_r4744098012
##########
sdks/python/apache_beam/typehints/typecheck.py:
##########
@@ -135,6 +136,12 @@ def __init__(self, dofn, type_hints, label=None):
self._input_hints = None
# TODO(robertwb): Multi-output.
self._output_type_hint = type_hints.simple_output_type(label)
+ # Runners unwrap TimestampedValue before passing elements downstream, so
+ # check the wrapped value unless the declared output hint explicitly
accepts
+ # TimestampedValue (e.g. `-> TimestampedValue` or `Any`).
+ self._unwrap_timestamped_value = (
+ self._output_type_hint is not None and
+ not is_consistent_with(TimestampedValue, self._output_type_hint))
Review Comment:
Thanks for applying this cleanly — one edge case I missed in my earlier
snippet: if a transform declares a `@typing.runtime_checkable` `Protocol` with
non-method (attribute) members via `.with_output_types(MyProto)`,
`is_consistent_with(TimestampedValue, self._output_type_hint)` delegates to
`issubclass()` and raises `TypeError: Protocols with non-method members don't
support issubclass()` during `TypeCheckVisitor` even when the DoFn never yields
a `TimestampedValue` (whereas `check_constraint` uses `isinstance()`, so it
passed on `master`).
Wrapping this in `try ... except TypeError: self._unwrap_timestamped_value =
True` avoids that regression:
```python
try:
self._unwrap_timestamped_value = (
self._output_type_hint is not None and
not is_consistent_with(TimestampedValue, self._output_type_hint))
except TypeError:
self._unwrap_timestamped_value = True
```
##########
CHANGES.md:
##########
@@ -173,6 +173,7 @@
* (Python) An unknown pipeline option is no longer given the value of a later
argument that does not directly follow it, which made `Pipeline.run()` and
`get_all_options(retain_unknown_options=True)` fail with `expected one
argument` for flags like `--unknown_flag --job_name=foo bar`
([#22434](https://github.com/apache/beam/issues/22434)).
* (Python) Fixed `WriteToJson` silently rounding floats to 10 decimal places:
it now defaults pandas' `double_precision` to 15, so values such as
`0.1234567890123` and `1e-11` are written correctly. Floats that need 16-17
significant digits may still be rounded
([#41102](https://github.com/apache/beam/issues/41102)).
* (Java) Makes some fixes to IcebergIO's hash distribution mode, which
sometimes wrote incorrect partition values.
([#41012](https://github.com/apache/beam/issues/41012)).
+* (Python) Fixed `Reify.Window`, `Reify.WindowInValue` and
`Reify.TimestampInValue` failing to encode their output when the input has an
element type, for example the output of `beam.Create`. Pipelines with untyped
input now get different coders for these transforms, which can break streaming
update compatibility. To update safely specify the pipeline option
`--update_compatibility_version=2.78.0`
([#41306](https://github.com/apache/beam/issues/41306)).
Review Comment:
This file has a merge conflict with `master` that is currently preventing
the `pull_request` CI workflows from running on `e577d725` — please merge
`master` to resolve it. (Minor wording nit while resolving: only `Reify.Window`
and `Reify.WindowInValue` change coders for untyped inputs;
`Reify.TimestampInValue` keeps the same `FastPrimitivesCoder` for the value.)
##########
sdks/python/apache_beam/typehints/typecheck.py:
##########
@@ -166,6 +173,8 @@ def type_check_output(o):
else:
# TODO(robertwb): Multi-output.
x = o.value if isinstance(o, (TaggedOutput, WindowedValue)) else o
+ if isinstance(x, TimestampedValue) and self._unwrap_timestamped_value:
Review Comment:
Optional nit: `runners/common.py` (`_maybe_propagate_windowing_info`)
unwraps `TaggedOutput` and then unwraps *either* `WindowedValue` *or*
`TimestampedValue`, not a `TimestampedValue` nested inside a `WindowedValue`.
Using `elif` matches runner behavior:
```python
x = o.value if isinstance(o, TaggedOutput) else o
if isinstance(x, WindowedValue):
x = x.value
elif isinstance(x, TimestampedValue) and self._unwrap_timestamped_value:
x = x.value
```
--
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]