title: Spark Dataframe UDF - Schema for type Any is not supported
body: <p>I am writing a Spark Scala UDF and facing "java.lang.UnsupportedOperationException: Schema for type Any is not supported"</p>
  
  <pre><code>import org.apache.spark.sql.expressions.UserDefinedFunction
  import org.apache.spark.sql.functions.udf
  
  val aBP = udf((bG: String, pS: String, bP: String, iOne: String, iTwo: String) =&gt; {
    if (bG != "I") {"NA"}
    else if (pS == "D")
      {if (iTwo != null) iOne else "NA"}
    else if (pS == "U")
      {if (bP != null) bP else "NA"}
  })
  </code></pre>
  
  <p>This is throwing error "java.lang.UnsupportedOperationException: Schema for type Any is not supported" </p>