reuvenlax commented on a change in pull request #10529: [BEAM-9044] Protobuf
options to Schema options
URL: https://github.com/apache/beam/pull/10529#discussion_r396253805
##########
File path:
sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoSchemaTranslator.java
##########
@@ -352,4 +354,49 @@ private static FieldType
beamFieldTypeFromSingularProtoField(
}
return fieldType;
}
+
+ private static Schema.Options getFieldOptions(FieldDescriptor
fieldDescriptor) {
+ return getOptions(fieldDescriptor.getOptions().getAllFields());
+ }
+
+ private static Schema.Options getSchemaOptions(Descriptors.Descriptor
descriptor) {
+ return getOptions(descriptor.getOptions().getAllFields());
+ }
+
+ private static Schema.Options getOptions(Map<FieldDescriptor, Object>
allFields) {
+ Schema.Options.Builder optionsBuilder = Schema.Options.builder();
+ for (Map.Entry<FieldDescriptor, Object> entry : allFields.entrySet()) {
+ FieldDescriptor fieldDescriptor = entry.getKey();
+ FieldType fieldType = beamFieldTypeFromProtoField(fieldDescriptor);
+
+ switch (fieldType.getTypeName()) {
+ case BYTE:
+ case BYTES:
+ case INT16:
+ case INT32:
+ case INT64:
+ case DECIMAL:
+ case FLOAT:
+ case DOUBLE:
+ case STRING:
+ case BOOLEAN:
+ case LOGICAL_TYPE:
+ case ROW:
+ case ARRAY:
+ case ITERABLE:
+ Field field = Field.of("OPTION", fieldType);
+ ProtoDynamicMessageSchema schema =
ProtoDynamicMessageSchema.forSchema(Schema.of(field));
+ optionsBuilder.setOption(
+ fieldDescriptor.getFullName(),
Review comment:
As mentioned above, I think we should add a well-known prefix here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services