title: Avro Schema to spark StructType
body: <p>This is effectively the same as my <a href="https://stackoverflow.com/questions/33807145/evolving-a-schema-with-spark-dataframe/">previous question</a>, but using Avro rather than JSON as the data format.</p>
  
  <p>I'm working with a Spark dataframe which could be loading data from one of a few different schema versions:</p>
  
  <pre><code>// Version One
  {"namespace": "com.example.avro",
   "type": "record",
   "name": "MeObject",
   "fields": [
       {"name": "A", "type": ["null", "int"], "default": null}
   ]
  }
  
  // Version Two
  {"namespace": "com.example.avro",
   "type": "record",
   "name": "MeObject",
   "fields": [
       {"name": "A", "type": ["null", "int"], "default": null},
       {"name": "B", "type": ["null", "int"], "default": null}
   ]
  }
  </code></pre>
  
  <p>I'm using <a href="https://github.com/databricks/spark-avro" rel="noreferrer">Spark Avro</a> to load the data.</p>
  
  <pre><code>DataFrame df = context.read()
    .format("com.databricks.spark.avro")
    .load("path/to/avro/file");
  </code></pre>
  
  <p>which may be a Version One file or Version Two file. However I'd like to be able to process it in an identical manner, with the unknown values set to "null". The recommendation in my previous question was to set the schema, however I do not want to repeat myself writing the schema in both a <code>.avro</code> file and as sparks <code>StructType</code> and friends. How can I convert the avro schema (either text file or the generated <code>MeObject.getClassSchema()</code>) into sparks <code>StructType</code>?</p>
  
  <p>Spark Avro has a <a href="https://github.com/databricks/spark-avro/blob/master/src/main/scala/com/databricks/spark/avro/SchemaConverters.scala" rel="noreferrer"><code>SchemaConverters</code></a>, but it is all private and  returns some strange internal object.</p>