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

[BEAM-2431] Add PipelineOptionsTranslation #3719

Closed
wants to merge 2 commits into from

Conversation

tgroh
Copy link
Member

@tgroh tgroh commented Aug 15, 2017

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

This converts a PipelineOptions instance to and from a Protobuf Struct.

Needs to be performed to send an entire job specification through the Job API.

This converts a PipelineOptions instance to and from a Protobuf Struct.
@tgroh
Copy link
Member Author

tgroh commented Aug 15, 2017

R: @kennknowles

@tgroh tgroh changed the title Add PipelineOptionsTranslation [BEAM-2431] Add PipelineOptionsTranslation Aug 15, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 69.97% when pulling dd73473 on tgroh:pipeline_options_translation into f7e8f88 on apache:master.

Copy link
Member

@kennknowles kennknowles left a comment

Choose a reason for hiding this comment

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

Fine as-is, but some comments.

@lukecwik might have suggestions.


@Test
public void testToFromProto() throws Exception {
PipelineOptionsTranslation.fromProto(PipelineOptionsTranslation.toProto(options));
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to check that you got the right thing back?

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to convert it to JSON and perform a JSON equivalence test.

Proto3 struct may do the equivalence check as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I need to add a call to getOptionsId for this to pass. Otherwise, done.

PipelineOptions withParsedSettings =
PipelineOptionsFactory.fromArgs("--jobName=my_job --appName=my_app").create();

return Arrays.asList(
Copy link
Member

Choose a reason for hiding this comment

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

nit: I like ImmutableList.of(...) more than Arrays.asList(...) just because you aren't actually converting an array and that's a bizarre Java-ism.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@lukecwik lukecwik left a comment

Choose a reason for hiding this comment

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

I don't think there is a better way unless you provide a direct mapping from Jackson's types to Protos types but that seems unnecessarily complex for a piece which isn't performance critical.


@Test
public void testToFromProto() throws Exception {
PipelineOptionsTranslation.fromProto(PipelineOptionsTranslation.toProto(options));
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to convert it to JSON and perform a JSON equivalence test.

Proto3 struct may do the equivalence check as well.

public static Struct toProto(PipelineOptions options) {
Struct.Builder builder = Struct.newBuilder();
try {
JsonFormat.parser().merge(MAPPER.writeValueAsString(options), builder);
Copy link
Member

Choose a reason for hiding this comment

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

It is a bit of a bummer to write to a JSON string only to parse it immediately. I don't have a strong opinion, but you might want to add a comment so the next person coming here is not shocked. And if they know a better way they can fix it. (but this is not high bandwidth so I don't think you should spend time trying to improve it unless there's something obvious)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Commented a touch, referencing this PR.

@asfgit asfgit closed this in a267ca8 Sep 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants