srinipunuru 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_r256548128
########## 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: Yup getNonNullUnionSchema just returns the original schema if it is not a union schema. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services