title: Scala UDF returning 'Schema for type Unit is not supported'
body: <p>I want to make changes to a column in the dataframe. The column is an Array for Integers. I want to replace an elements of the array, taking index from another array and replacing that element with an element from third array. Example: I have three columns C1, C2, C3 all three arrays. I want to replace elements in C3 as follows.</p>
  
  <pre><code>C3[C2[i]] = C1[i].
  </code></pre>
  
  <p>I wrote the following UDF:</p>
  
  <pre><code>def UpdateHist = udf((CRF_count: Seq[Long], Day: Seq[String], History: Seq[Int])=&gt; for(i &lt;- 0 to Day.length-1){History.updated(Day(i).toInt-1 , CRF_count(i).toInt)})
  </code></pre>
  
  <p>and executed this:</p>
  
  <pre><code>histdate3.withColumn("History2", UpdateHist2(col("CRF_count"), col("Day"), col("History"))).show()
  </code></pre>
  
  <p>But its returning an error as below:</p>
  
  <pre><code>scala&gt; histdate3.withColumn("History2", UpdateHist2(col("CRF_count"), col("Day"), col("History"))).show()
  </code></pre>
  
  <blockquote>
    <p>java.lang.UnsupportedOperationException: Schema for type Unit is not supported
      at org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:733)
      at org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:671)
      at org.apache.spark.sql.functions$.udf(functions.scala:3100)
      at UpdateHist2(:25)
      ... 48 elided</p>
  </blockquote>
  
  <p>I think I'm returning some different type, a View type which is not supported. Please help me how I can solve this.</p>