[GitHub] [beam] rworley-monster commented on a change in pull request #12367: [BEAM-10564] Support more Avro field name formats when mapping to Jav…

2020-09-14 Thread GitBox


rworley-monster commented on a change in pull request #12367:
URL: https://github.com/apache/beam/pull/12367#discussion_r487819806



##
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/AvroUtils.java
##
@@ -601,12 +601,26 @@ private void readObject(ObjectInputStream in) throws 
IOException, ClassNotFoundE
 private Map getMapping(Schema schema) {
   Map mapping = Maps.newHashMap();
   for (Field field : schema.getFields()) {
-String underscore = 
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getName());
-mapping.put(underscore, field.getName());
+String fieldName = field.getName();
+String getter;
+if (fieldName.contains("_")) {
+  if (Character.isLowerCase(fieldName.charAt(0))) {
+// field_name -> fieldName
+getter = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, 
fieldName);
+  } else {
+// FIELD_NAME -> fIELDNAME
+getter = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, 
fieldName.replace("_", ""));

Review comment:
   I have added an extended comment for this conversion and updated the 
existing test Avro schema to cover the new mappable field name styles.  Can you 
please confirm that this is acceptable?





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:
us...@infra.apache.org




[GitHub] [beam] rworley-monster commented on a change in pull request #12367: [BEAM-10564] Support more Avro field name formats when mapping to Jav…

2020-09-01 Thread GitBox


rworley-monster commented on a change in pull request #12367:
URL: https://github.com/apache/beam/pull/12367#discussion_r481200851



##
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/AvroUtils.java
##
@@ -601,12 +601,26 @@ private void readObject(ObjectInputStream in) throws 
IOException, ClassNotFoundE
 private Map getMapping(Schema schema) {
   Map mapping = Maps.newHashMap();
   for (Field field : schema.getFields()) {
-String underscore = 
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getName());
-mapping.put(underscore, field.getName());
+String fieldName = field.getName();
+String getter;
+if (fieldName.contains("_")) {
+  if (Character.isLowerCase(fieldName.charAt(0))) {
+// field_name -> fieldName
+getter = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, 
fieldName);
+  } else {
+// FIELD_NAME -> fIELDNAME
+getter = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, 
fieldName.replace("_", ""));

Review comment:
   Sure, I will add tests for all of the cases as soon as I have time.  
Hopefully within one or two weeks.





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:
us...@infra.apache.org




[GitHub] [beam] rworley-monster commented on a change in pull request #12367: [BEAM-10564] Support more Avro field name formats when mapping to Jav…

2020-08-18 Thread GitBox


rworley-monster commented on a change in pull request #12367:
URL: https://github.com/apache/beam/pull/12367#discussion_r472156800



##
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/AvroUtils.java
##
@@ -601,12 +601,26 @@ private void readObject(ObjectInputStream in) throws 
IOException, ClassNotFoundE
 private Map getMapping(Schema schema) {
   Map mapping = Maps.newHashMap();
   for (Field field : schema.getFields()) {
-String underscore = 
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getName());
-mapping.put(underscore, field.getName());
+String fieldName = field.getName();
+String getter;
+if (fieldName.contains("_")) {
+  if (Character.isLowerCase(fieldName.charAt(0))) {
+// field_name -> fieldName
+getter = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, 
fieldName);
+  } else {
+// FIELD_NAME -> fIELDNAME
+getter = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, 
fieldName.replace("_", ""));

Review comment:
   When Avro compiles a schema to a Java class, it will take a field named 
`FIELD_NAME` and create a getter named `getFIELDNAME`.  So this method needs to 
produce getter field name `fIELDNAME`.
   
   After some trial and error, I found I could produce this if I remove the 
underscore and convert it from `UPPER_CAMEL`.  When I use `UPPER_UNDERSCORE` 
(with or without the underscore in the field name), it produces a getter field 
name of `fieldName` or `fieldname`, which won't map to the `getFIELDNAME` 
method.





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:
us...@infra.apache.org