title: How to create UDF from Scala methods (to compute md5)?
body: <p>I would like to build one UDF from two already working functions. I'm trying to calculate a md5 hash as a new column to an existing Spark Dataframe.</p>
  
  <pre><code>def md5(s: String): String = { toHex(MessageDigest.getInstance("MD5").digest(s.getBytes("UTF-8")))}
  def toHex(bytes: Array[Byte]): String = bytes.map("%02x".format(_)).mkString("")
  </code></pre>
  
  <p><strong>Structure</strong> (what i have so far)</p>
  
  <pre><code>val md5_hash: // UDF Implementation
  val sqlfunc = udf(md5_hash)
  val new_df = load_df.withColumn("New_MD5_Column", sqlfunc(col("Duration")))
  </code></pre>
  
  <p>Unfortunately i don't know how to propably implement the function as UDF.</p>