Uh oh!
There was an error while loading. Please reload this page.
Update portable schema representation and java SchemaTranslation - #8853
Conversation
… SchemaTranslationTest
kennknowles
left a comment
There was a problem hiding this comment.
This is great, nice and clear diff. Meaningful change. The only comment that is actionable here is that it might be an opportune time to reset the 0 value for the AtomicType enum.
| // Experimental: A representation of a Beam Schema. | ||
| message Schema { | ||
| enum TypeName { | ||
| enum AtomicType { |
There was a problem hiding this comment.
Isn't 0 in an enum supposed to be reserved for unknown? It is wise, because of defaulting in proto libs.
There was a problem hiding this comment.
Yes, to my knowledge specifically adding an UNSPECIFIED with a value of 0 will make this clearer.
For example:
| ArrayType array_type = 3; | ||
| MapType map_type = 4; | ||
| Schema row_schema = 5; | ||
| Schema row_type = 5; |
There was a problem hiding this comment.
Proto best practice I think is to go ahead and have a RowType message with one field. It has overhead, yes.
There was a problem hiding this comment.
Done. Agreed this is much cleaner
| .put(TypeName.BYTES, RunnerApi.Schema.AtomicType.BYTES) | ||
| .build(); | ||
| private static final String URN_BEAM_LOGICAL_DATETIME = "urn:beam:logical:datetime"; |
There was a problem hiding this comment.
Two stylistic nits:
- We tend to omit the
urn, don't we? While it does make a valid URI out of the thing, it seems a bit silly. - I would leave out
logicalbut put in something liketypeorschema_typeorfieldtypeto namespace.
There was a problem hiding this comment.
Done. I went with fieldtype
| .put(TypeName.ROW, RunnerApi.Schema.TypeName.ROW) | ||
| .put(TypeName.LOGICAL_TYPE, RunnerApi.Schema.TypeName.LOGICAL_TYPE) | ||
| private static final BiMap<TypeName, RunnerApi.Schema.AtomicType> ATOMIC_TYPE_MAPPING = |
There was a problem hiding this comment.
TBH I find a switch clearer than a map lookup, and it takes the same amount of code space. Not for this PR, in which you are just editing the existing structure not restructuring.
| switch (typeName) { | ||
| case ROW: | ||
| fieldType = FieldType.row(fromProto(protoFieldType.getRowSchema())); | ||
| switch (protoFieldType.getTypeInfoCase()) { |
There was a problem hiding this comment.
Another not-for-this PR comment that this would be cleaner with the switch in a function so the branches could all return.
lukecwik
commented
Jun 19, 2019
Is the beam_runner_api.proto the right place to put all the schema stuff? |
TheNeuralBit
commented
Jun 19, 2019
I guess I don't have a strong opinion, I was just updating it in place. Do you think it should get it's own schema.proto file? |
kennknowles
commented
Jun 20, 2019
I think it would be great to have a separate |
TheNeuralBit
commented
Jun 20, 2019
Agreed. I can follow-up with PR(s) for that move and the other code cleanup suggestions. |
robertwb
commented
Jun 25, 2019
LGTM too. Thanks. |
…ion (apache#8853)" This reverts commit e65c176.
…Translation (apache#8853)"" This reverts commit dbcb14c.
…ion (apache#8853)" This reverts commit e65c176.
Also adds tests in SchemaTranslationTest.
Things that are not currently included in this PR:
Schema.FieldTypeand they are mapped to the appropriate URNs when converting to/from the proto representation.Post-Commit Tests Status (on master branch)
Pre-Commit Tests Status (on master branch)
See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.
R: @reuvenlax, @robertwb, @kennknowles