-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
This converts a PipelineOptions instance to and from a Protobuf Struct.
R: @kennknowles |
There was a problem hiding this 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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
Follow this checklist to help us incorporate your contribution quickly and easily:
[BEAM-XXX] Fixes bug in ApproximateQuantiles
, where you replaceBEAM-XXX
with the appropriate JIRA issue.mvn clean verify
to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.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.