Skip to content
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

Propogate field_descriptions to RowTypeConstraint #32776

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

Polber
Copy link
Contributor

@Polber Polber commented Oct 14, 2024

#29561 introduced the ability to persist Field descriptions defined in Cross-language transform configs as shown here:

descriptions = {}
for field in schema.fields:
try:
field_py_type = self.typing_from_runner_api(field.type)
if isinstance(field_py_type, row_type.RowTypeConstraint):
field_py_type = field_py_type.user_type
except ValueError as e:
raise ValueError(
"Failed to decode schema due to an issue with Field proto:\n\n"
f"{text_format.MessageToString(field)}") from e
descriptions[field.name] = field.description
subfields.append((field.name, field_py_type))
user_type = NamedTuple(type_name, subfields)
# Define a reduce function, otherwise these types can't be pickled
# (See BEAM-9574)
setattr(
user_type,
'__reduce__',
_named_tuple_reduce_method(schema.SerializeToString()))
setattr(user_type, "_field_descriptions", descriptions)
setattr(user_type, row_type._BEAM_SCHEMA_ID, schema.id)

However, this information is dropped when converting the NamedTuple (parsed from the proto) into a RowTypeConstraint type.

This PR propagates this optional data so that when converting from RowTypeConstraint to schema_pb2.Schema (runner_api), the field descriptions can be included in the proto.


This is also helpful for Beam YAML auto documentation which attempts to use the description field from the schema_pb2.Schema, but is not populated by default. After this change, the auto documentation can pull in decsriptions for cross-language (Java) transforms annotated with @SchemaFieldDescription


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@Polber
Copy link
Contributor Author

Polber commented Oct 14, 2024

R: @robertwb

This PR fixes the issue with YAML auto docs not pulling in Java transform parameter descriptions.

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@liferoad liferoad requested a review from robertwb October 23, 2024 14:18
@robertwb robertwb merged commit 8b1ca21 into apache:master Oct 29, 2024
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants