How do I call a UDF on a Spark DataFrame using JAVA?
<p>Similar question as <a href="https://stackoverflow.com/questions/33829479/spark-sql-how-to-call-udf-from-dataframe-operation-using-java">here</a>, but don't have enough points to comment there. </p>

<p>According to the latest Spark <a href="https://spark.apache.org/docs/latest/sql-programming-guide.html#udf-registration-moved-to-sqlcontextudf-java--scala" rel="noreferrer">documentation</a> an <code>udf</code> can be used in two different ways, one with SQL and another with a DataFrame. I found multiple examples of how to use an <code>udf</code> with sql, but have not been able to find any on how to use a <code>udf</code> directly on a DataFrame. </p>

<p>The solution provided by the o.p. on the question linked above uses <code>__callUDF()__</code> which is <code>_deprecated_</code> and will be removed in Spark 2.0 according to the Spark Java API documentation. There, it says:</p>

<blockquote>
  <p>"since it's redundant with udf()"</p>
</blockquote>

<p>so this means I should be able to use <code>__udf()__</code> to cal a my <code>udf</code>, but I can't figure out how to do that. I have not stumbled on anything that spells out the syntax for Java-Spark programs. What am I missing?</p>

<pre><code>import org.apache.spark.sql.api.java.UDF1;
.
.    
UDF1 mode = new UDF1&lt;String[], String&gt;() {
    public String call(final String[] types) throws Exception {
        return types[0];
    }
};

sqlContext.udf().register("mode", mode, DataTypes.StringType);
df.???????? how do I call my udf (mode) on a given column of my DataFrame df?
</code></pre>