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] Implement basic java mapping operations. #28657

Merged
merged 10 commits into from
Oct 31, 2023

Conversation

robertwb
Copy link
Contributor

This will allow one to use the MapToFields transform with java expressions (callables, etc.)

This hasn't been wired up to Python yet, but is a good intermediate milestone. We'll also want to follow up with similar implementations for Filter (which can borrow the same UDF logic) and Explode (no UDFs involved).


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.

@github-actions github-actions bot added the java label Sep 25, 2023
@robertwb
Copy link
Contributor Author

R: @Polber

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the yaml label Oct 6, 2023

@Nullable
@SuppressWarnings("all")
public abstract ErrorHandling getError_handling();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for naming these with underscores when they can be remapped by the YAML provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I can go ahead and fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a UDF file test? testNamedFunctionUdf and testClassMethodUdf cover the name parameter, but what about the path?

Also, should this functionality (specifying only name) be included in the python MapToFields logic? It could essentially replace PyTransform, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Creating a full jar seemed a bit out-of-scope for a unit test (and that's not where the complexity was). IMHO that could wait until we have the integration testing framework.

As for using name for Python, this is essentially the equivalent to "callable" where you can pass a fully-qualified python name (as functions and classes are first class objects in Python, unlike Java). (Also, in Java, even if the file is specified, one still needs the fully qualified name.)

@robertwb
Copy link
Contributor Author

The Python failures are irrelevant.

Comment on lines 241 to 256
private static FunctionAndType createFunctionFromName(String name, String path)
throws ReflectiveOperationException, MalformedURLException {
ClassLoader classLoader =
path == null
? ClassLoader.getSystemClassLoader()
: new URLClassLoader(
new URL[] {new URL("file://" + path)}, ClassLoader.getSystemClassLoader());
String className, methodName = null;
if (name.indexOf("::") == -1) {
className = name;
methodName = null;
} else {
String[] parts = name.split("::", 2);
className = parts[0];
methodName = parts[1];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@robertwb Shouldn't there be support for reading a file from GCS in this logic by 2.52?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see that as as critical for 2.52 (v.s. the basic functionality of supporting expressions), but we could try to get that in as a follow-up.

Copy link
Contributor

Choose a reason for hiding this comment

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

My only concern would be if a user specified a GCS path in their pipeline which uses the python MapToFields, but then updates the pipeline to use more Java transforms, causing the MapToFields to switch to the Java implementation.

Is there a way to force an SDK implementation for a transform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here the language is explicitly specified; there's no automatic switching between the two. (E.g. a python script is not interchangeable with a java jar).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and implemented this. Ideally it'd use the artifact service, but we don't yet have a way to declare that from a transform.

Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Merging #28657 (5fd6532) into master (42586c4) will decrease coverage by 0.05%.
Report is 91 commits behind head on master.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #28657      +/-   ##
==========================================
- Coverage   38.37%   38.32%   -0.05%     
==========================================
  Files         686      688       +2     
  Lines      101685   101844     +159     
==========================================
+ Hits        39017    39033      +16     
- Misses      61088    61231     +143     
  Partials     1580     1580              
Flag Coverage Δ
python 29.93% <ø> (-0.05%) ⬇️

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

see 12 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@robertwb
Copy link
Contributor Author

Run Java PreCommit

@robertwb robertwb merged commit b513420 into apache:master Oct 31, 2023
97 of 100 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.

2 participants