Search in sources :

Example 1 with UserDefinedFunction

use of org.apache.spark.sql.expressions.UserDefinedFunction in project kylo by Teradata.

the class DataSetProviderUtilV2 method map.

/**
 * Applies the specified function to the specified field of the data set.
 */
@Nonnull
static Dataset<Row> map(@Nonnull final Dataset<Row> dataSet, @Nonnull final String fieldName, @Nonnull final Function1 function, @Nonnull final DataType returnType) {
    final Seq<Column> inputs = Seq$.MODULE$.<Column>newBuilder().$plus$eq(dataSet.col(fieldName)).result();
    final UserDefinedFunction udf = new UserDefinedFunction(function, returnType, Option$.MODULE$.<Seq<DataType>>empty());
    return dataSet.withColumn(fieldName, udf.apply(inputs));
}
Also used : UserDefinedFunction(org.apache.spark.sql.expressions.UserDefinedFunction) Column(org.apache.spark.sql.Column) DataType(org.apache.spark.sql.types.DataType) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)1 Column (org.apache.spark.sql.Column)1 UserDefinedFunction (org.apache.spark.sql.expressions.UserDefinedFunction)1 DataType (org.apache.spark.sql.types.DataType)1