private Schema wrapInUnionWithNull(Schema schema) {
    Schema wrappedSchema = schema;
    switch (schema.getType()) {
      case NULL:
        break;
      case UNION:
        List<Schema> existingSchemas = removeDuplicateNullSchemas(schema.getTypes());
        wrappedSchema = Schema.createUnion(existingSchemas);
        break;
      default:
        wrappedSchema = Schema.createUnion(Arrays.asList(Schema.create(Schema.Type.NULL), schema));
    }

    return wrappedSchema;
  }
Converts Hive schema to avro schema

@param columnNames Names of the hive columns
@param columnTypes Hive Column types
@param namespace   Namespace of Avro schema
@param name        Avro schema name
@param doc         Avro schema doc
@return Avro Schema
serde/src/java/org/apache/hadoop/hive/serde2/avro/TypeInfoToSchema.java