samza-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] atoomula commented on a change in pull request #916: End to end test case for union type with subRecord
Date Wed, 13 Feb 2019 15:38:38 GMT
atoomula commented on a change in pull request #916: End to end test case for union type with
subRecord
URL: https://github.com/apache/samza/pull/916#discussion_r256438362
 
 

 ##########
 File path: samza-sql/src/main/java/org/apache/samza/sql/avro/AvroRelConverter.java
 ##########
 @@ -283,4 +278,66 @@ public Object convertToJavaObject(Object avroObj, Schema schema) {
         return avroObj;
     }
   }
+
+  private boolean isSchemaCompatible(Object avroObj, Schema unionSchema) {
+    if (unionSchema.getType() == Schema.Type.NULL && avroObj == null) {
+      return true;
+    }
+    switch (unionSchema.getType()) {
+      case RECORD:
+        return avroObj instanceof IndexedRecord;
+      case ARRAY:
+        return avroObj instanceof GenericData.Array || avroObj instanceof List;
+      case MAP:
+        return avroObj instanceof Map;
+      case FIXED:
+        return avroObj instanceof GenericData.Fixed;
+      case BYTES:
+        return avroObj instanceof ByteBuffer;
+      case FLOAT:
+        return avroObj instanceof Float;
+      default:
+        return true;
+    }
+  }
+
+  private static boolean isSchemaCompatibleWithRelObj(Object relObj, Schema unionSchema)
{
+    if (unionSchema.getType() == Schema.Type.NULL && relObj == null) {
+      return true;
+    }
+    switch (unionSchema.getType()) {
+      case RECORD:
+        return relObj instanceof SamzaSqlRelRecord;
+      case ARRAY:
+        return relObj instanceof List;
+      case MAP:
+        return relObj instanceof Map;
+      case FIXED:
+        return relObj instanceof ByteString;
+      case BYTES:
+        return relObj instanceof ByteString;
+      case FLOAT:
+        return relObj instanceof Float || relObj instanceof Double;
+      default:
+        return true;
+    }
+  }
+
+  // Two non-nullable types in a union is not yet supported.
+  public static Schema getNonNullUnionSchema(Schema schema) {
 
 Review comment:
   How would this work if it is called from line 198 or from other complex types below it
? Wouldn't this function always return the same schema as the type would be the complex type
it is called from ? I think I added that code. But it doesn't make sense looking at it now.
It makes sense if it is called from convertToGenericRecord().

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message