Class SchemaUtils


  • public class SchemaUtils
    extends java.lang.Object
    • Method Detail

      • annotateValueSchema

        public static org.apache.avro.Schema annotateValueSchema​(org.apache.avro.Schema schema)
        Annotate all the top-level map field and string array field of the input schema to use Java String as key.
        Parameters:
        schema - the input value schema to be annotated.
        Returns:
        Annotated value schema.
      • annotateUpdateSchema

        public static org.apache.avro.Schema annotateUpdateSchema​(org.apache.avro.Schema schema)
        Annotate all the top-level map field and string array of the update schema to use Java String as key. This method will make sure field update and collection merging operations of these fields are annotated.
        Parameters:
        schema - the input update schema to be annotated.
        Returns:
        Annotated update schema.
      • annotateRmdSchema

        public static org.apache.avro.Schema annotateRmdSchema​(org.apache.avro.Schema schema)
        Annotate all the top-level map and string array's deleted elements field of the RMD schema to use Java String as key. This method will make sure deleted elements field of these fields are annotated.
        Parameters:
        schema - the input update schema to be annotated.
        Returns:
        Annotated update schema.
      • getAnnotatedValueSchemaEntry

        public static SchemaEntry getAnnotatedValueSchemaEntry​(SchemaEntry schemaEntry)
        Create a new SchemaEntry for value schema annotation.
        Parameters:
        schemaEntry - Input SchemaEntry, containing the value schema to be annotated.
        Returns:
        Annotated value schema in a newly created SchemaEntry
      • unwrapOptionalUnion

        public static org.apache.avro.Schema.Type unwrapOptionalUnion​(org.apache.avro.Schema fieldSchema)
        This function returns the type of the field if and only if it has a single non-null type. In cases where the field is a union, it will return the type of the non-null branch as long as there is at most one such branch, otherwise it will return Schema.Type.UNION.
      • validateFieldSchemaType

        public static void validateFieldSchemaType​(java.lang.String fieldName,
                                                   org.apache.avro.Schema fieldSchema,
                                                   org.apache.avro.Schema.Type expectedType)
        This method checks if the field contains expected type. It relies on unwrapOptionalUnion(Schema) to retrieve the type from the field if incoming field is union. If it could not find expected type, or the incoming union is not valid for processing, it will throw IllegalStateException