[ 
https://issues.apache.org/jira/browse/GOBBLIN-987?focusedWorklogId=351190&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-351190
 ]

ASF GitHub Bot logged work on GOBBLIN-987:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Nov/19 01:25
            Start Date: 29/Nov/19 01:25
    Worklog Time Spent: 10m 
      Work Description: ahmedahamid commented on pull request #2833: 
[GOBBLIN-987] Reject unrecognized Enum symbols in 
JsonRecordAvroSchemaToAvroConverter
URL: https://github.com/apache/incubator-gobblin/pull/2833#discussion_r351953747
 
 

 ##########
 File path: 
gobblin-core/src/main/java/org/apache/gobblin/converter/avro/JsonElementConversionWithAvroSchemaFactory.java
 ##########
 @@ -165,7 +166,10 @@ public EnumConverter(String fieldName, boolean nullable, 
String sourceType, Sche
 
     @Override
     Object convertField(JsonElement value) {
-      return new GenericData.EnumSymbol(this.schema, value.getAsString());
+      String valueString = value.getAsString();
+      Validate.isTrue(this.enumSet.contains(valueString),
 
 Review comment:
   No problem. The code already has a dependency on commons lang3 (I checked 
the `build.gradle` of the `gobblin-core` module) but I do agree regarding 
consistency.
   
   One more thing: I had to make a tiny change to line #162 in 
`JsonElementConversionWithAvroSchemaFactory.java` because the code wasn't 
picking the enum name correctly. It was retrieving the type name instead, which 
is always `enum`. So, now the exception message reads as follows
   ```
   PURPLE is not one of the valid symbols for the 
org.apache.gobblin.test.Colors enum: [RED, GREEN, BLUE]
   ```
 
----------------------------------------------------------------
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 351190)
    Time Spent: 40m  (was: 0.5h)

> JsonRecordAvroSchemaToAvroConverter does not reject unrecognized Enum symbols
> -----------------------------------------------------------------------------
>
>                 Key: GOBBLIN-987
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-987
>             Project: Apache Gobblin
>          Issue Type: Bug
>            Reporter: Ahmed Abdul Hamid
>            Priority: Major
>         Attachments: invalid-enum-unit-test.patch
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Here is a failing unit test that demonstrates the issue we encounter when we 
> attempt to encode the records produced by 
> {{JsonRecordAvroSchemaToAvroConverter}} with unrecognized Enum symbols: 
> [^invalid-enum-unit-test.patch]
> Here's how to apply the patch and run the test:
> {code:bash}
> $ git apply invalid-enum-unit-test.patch$ 
> $ ./gradlew :gobblin-core:test --tests *testEnumConversion*  {code}
> Here's the output:
> {code:java}
> java.lang.NullPointerException: null of string in field fieldToIgnore of 
> org.apache.gobblin.test.TestRecord
>       at 
> org.apache.avro.generic.GenericDatumWriter.npe(GenericDatumWriter.java:132)
>       at 
> org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:126)
>       at 
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
>       at 
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:60)
>       at 
> org.apache.gobblin.converter.avro.JsonRecordAvroSchemaToAvroConverterTest.testEnumConversion(JsonRecordAvroSchemaToAvroConverterTest.java:82)
>  {code}
> The root cause of the issue is that {{JsonRecordAvroSchemaToAvroConverter}} 
> allows unrecognized Enum symbols not declared in the specified Avro schema.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to