title: Spark DF: Schema for type Unit is not supported
body: <p>I am new to Scala and Spark and trying to build on some samples I found. Essentially I am trying to call a function from within a data frame to get State from zip code using Google API..
  I have the code working separately but not together ;(
  Here is the piece of code not working...</p>
  
  <pre><code>Exception in thread "main" java.lang.UnsupportedOperationException: Schema for type Unit is not supported
      at org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:716)
      at org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:654)
      at org.apache.spark.sql.functions$.udf(functions.scala:2837)
      at MovieRatings$.getstate(MovieRatings.scala:51)
      at MovieRatings$$anonfun$4.apply(MovieRatings.scala:48)
      at MovieRatings$$anonfun$4.apply(MovieRatings.scala:47)...
  Line 51 starts with def getstate = udf {(zipcode:String)...
  ...
  </code></pre>
  
  <p><strong>code:</strong></p>
  
  <pre><code> userDF.createOrReplaceTempView("Users")
      // SQL statements can be run by using the sql methods provided by Spark
     val zipcodesDF = spark.sql("SELECT distinct zipcode, zipcode as state FROM Users")
   //  zipcodesDF.map(zipcodes =&gt; "zipcode: " + zipcodes.getAs[String]("zipcode") + getstate(zipcodes.getAs[String]("zipcode"))).show()
    val colNames = zipcodesDF.columns
  val cols = colNames.map(cName =&gt; zipcodesDF.col(cName))
  val theColumn = zipcodesDF("state")
  val mappedCols = cols.map(c =&gt; 
    if (c.toString() == theColumn.toString()) getstate(c).as("transformed") else c)
    val newDF = zipcodesDF.select(mappedCols:_*).show()
    }
   def getstate = udf {(zipcode:String) =&gt; {
  val url = "http://maps.googleapis.com/maps/api/geocode/json?address="+zipcode
  val result = scala.io.Source.fromURL(url).mkString
  val address = parse(result) 
  val shortnames = for {
           JObject(address_components) &lt;- address
           JField("short_name", short_name)  &lt;- address_components
            } yield short_name
  val state = shortnames(3)
  //return state.toString()
  val stater = state.toString()
  
  }
    }
  </code></pre>