gobblin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hut...@apache.org
Subject incubator-gobblin git commit: [GOBBLIN-295] Make missing nullable fields default to null
Date Fri, 20 Oct 2017 22:04:33 GMT
Repository: incubator-gobblin
Updated Branches:
  refs/heads/master 0ee3cfdca -> 68456c620


[GOBBLIN-295] Make missing nullable fields default to null

Closes #2146 from jack-moseley/jsontoavro_nullable


Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/68456c62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/68456c62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/68456c62

Branch: refs/heads/master
Commit: 68456c620c3a759d47bab4dff43d7b5ad6e46fdd
Parents: 0ee3cfd
Author: Jack Moseley <jmoseley@linkedin.com>
Authored: Fri Oct 20 15:04:25 2017 -0700
Committer: Hung Tran <hutran@linkedin.com>
Committed: Fri Oct 20 15:04:25 2017 -0700

----------------------------------------------------------------------
 .../avro/JsonRecordAvroSchemaToAvroConverter.java     | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/68456c62/gobblin-core/src/main/java/org/apache/gobblin/converter/avro/JsonRecordAvroSchemaToAvroConverter.java
----------------------------------------------------------------------
diff --git a/gobblin-core/src/main/java/org/apache/gobblin/converter/avro/JsonRecordAvroSchemaToAvroConverter.java
b/gobblin-core/src/main/java/org/apache/gobblin/converter/avro/JsonRecordAvroSchemaToAvroConverter.java
index 97f0121..11f85f4 100644
--- a/gobblin-core/src/main/java/org/apache/gobblin/converter/avro/JsonRecordAvroSchemaToAvroConverter.java
+++ b/gobblin-core/src/main/java/org/apache/gobblin/converter/avro/JsonRecordAvroSchemaToAvroConverter.java
@@ -31,7 +31,7 @@ import org.apache.gobblin.converter.ToAvroConverterBase;
 
 import com.google.common.base.Preconditions;
 import com.google.gson.JsonObject;
-import com.google.common.base.Preconditions;
+import com.google.gson.JsonNull;
 import com.google.common.base.Splitter;
 
 
@@ -84,10 +84,6 @@ public class JsonRecordAvroSchemaToAvroConverter<SI> extends ToAvroConverterBase
         continue;
       }
 
-      if (inputRecord.get(field.name()) == null) {
-        throw new DataConversionException("Field missing from record: " + field.name());
-      }
-
       Schema.Type type = field.schema().getType();
       boolean nullable = false;
       Schema schema = field.schema();
@@ -107,6 +103,14 @@ public class JsonRecordAvroSchemaToAvroConverter<SI> extends ToAvroConverterBase
         } else {
           throw new DataConversionException("Unions must be size 2, and contain one null");
         }
+
+        if (inputRecord.get(field.name()) == null) {
+          inputRecord.add(field.name(), JsonNull.INSTANCE);
+        }
+      }
+
+      if (inputRecord.get(field.name()) == null) {
+        throw new DataConversionException("Field missing from record: " + field.name());
       }
 
       if (type.equals(Schema.Type.RECORD)) {


Mime
View raw message