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

[YAML] Allow constants and simple comparisons in generic expressions. #31455

Merged
merged 11 commits into from
Jun 11, 2024

Conversation

robertwb
Copy link
Contributor


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.

Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@robertwb
Copy link
Contributor Author

R: @Polber

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

@robertwb
Copy link
Contributor Author

robertwb commented Jun 3, 2024

The Java WindowedWordCountIT failures look unrelated.

Copy link
Contributor

@Polber Polber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks really good - my one concern is the clunkiness of string literals... I know that YAML treats everything as a string, so you need some way of emphasizing when an expression should be treated as a string literal, but specifying '"some string"' feels messy. Is there a way to modify the SafeLineLoader to preserve explicit double quotes?

Something like https://stackoverflow.com/a/67917266 perhaps

return

raise ValueError(
f"Missing language specification or unknown input fields: {expr}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should this message refer to expression rather than input fields?

Suggested change
f"Missing language specification or unknown input fields: {expr}")
f"Missing language specification or invalid generic expression: {expr}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I kept the "unkown input fields" as a missing/typo input name is still a quite likely error here we should point to.

Comment on lines 6 to 12
# (the# Row(word='License'); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an# Row(word='AS IS' BASIS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI all of the test files have this error, so not sure what is generating this license, but it appears to not like single quotes

Suggested change
# (the# Row(word='License'); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an# Row(word='AS IS' BASIS,
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here and #31480 for the rest.

@robertwb
Copy link
Contributor Author

robertwb commented Jun 3, 2024

Overall, looks really good - my one concern is the clunkiness of string literals... I know that YAML treats everything as a string, so you need some way of emphasizing when an expression should be treated as a string literal, but specifying '"some string"' feels messy. Is there a way to modify the SafeLineLoader to preserve explicit double quotes?

I agree that it's a bit clunky, but I do want the value to be a string that contains quotes in it as a literal. Shouldn't be too common, and it's what I would also use if I was specifying an explicit language.

Something like https://stackoverflow.com/a/67917266 perhaps

This seems to be about preserving the quoting style in writing, but it seems dangerous to treat 'possible_var' and "possible_var" differently in parsing.

Copy link
Contributor Author

@robertwb robertwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed comments, PTAL.

robertwb and others added 2 commits June 4, 2024 14:38
Co-authored-by: Ahmed Abualsaud <65791736+ahmedabu98@users.noreply.github.com>
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 73.68421% with 15 lines in your changes missing coverage. Please review.

Project coverage is 71.15%. Comparing base (bb4ad99) to head (5c16329).
Report is 46 commits behind head on master.

Current head 5c16329 differs from pull request most recent head e41b014

Please upload reports for the commit e41b014 to get more accurate results.

Files Patch % Lines
sdks/python/apache_beam/yaml/yaml_mapping.py 72.22% 15 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #31455      +/-   ##
============================================
+ Coverage     71.14%   71.15%   +0.01%     
  Complexity     3008     3008              
============================================
  Files          1055     1055              
  Lines        133439   133434       -5     
  Branches       3248     3248              
============================================
+ Hits          94929    94948      +19     
+ Misses        35382    35358      -24     
  Partials       3128     3128              
Flag Coverage Δ
python 81.30% <73.68%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@robertwb
Copy link
Contributor Author

robertwb commented Jun 7, 2024

Any more thoughts on this?

@Polber
Copy link
Contributor

Polber commented Jun 7, 2024

Any more thoughts on this?

I agree with your comments above - I still think it's clunky, but I agree the use-case is limited and this way it is more explicit.

I think biggest thing is to add documentation and possibly adjusting the error message to point out that the expression should include single quotes around a double quoted string for string literals (which could be displayed only if regex does not match it to a number).

@robertwb
Copy link
Contributor Author

robertwb commented Jun 7, 2024

I added a section to the documentation and referred to that in the error message.

@robertwb robertwb merged commit c2207d8 into apache:master Jun 11, 2024
114 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants