title: How to read Spark SQL UserDefinedType from csv
body: <p>I am trying to define a UserDefinedType based on String but different from StringType in Spark 2.4.1 but it looks like there is a bug in Spark or I am doing smth incorrectly.</p>
  
  <p>I define my type as follows:</p>
  
  <pre class="lang-scala prettyprint-override"><code>class MyType extends UserDefinedType[MyValue] {
    override def sqlType: DataType = StringType
    ...
  }
  
  @SQLUserDefinedType(udt = classOf[MyType])
  case class MyValue
  
  </code></pre>
  
  <p>I expect it to be read and stored as String with just a custom SQL type. In fact Spark can't read the string at all:</p>
  
  <pre><code>java.lang.ClassCastException: org.apache.spark.sql.execution.datasources.csv.UnivocityParser$$anonfun$makeConverter$11 cannot be cast to org.apache.spark.unsafe.types.UTF8String
      at org.apache.spark.sql.catalyst.expressions.BaseGenericInternalRow$class.getUTF8String(rows.scala:46)
      at org.apache.spark.sql.catalyst.expressions.GenericInternalRow.getUTF8String(rows.scala:195)
      at org.apache.spark.sql.catalyst.expressions.JoinedRow.getUTF8String(JoinedRow.scala:102)
  
  </code></pre>
  
  <p>I think the problem is with UnivocityParser.makeConverter that doesn't return (String => Any) function but (String => (String => Any)) in the case of UDT</p>