Search in sources :

Example 1 with UserDefinedFunction

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

the class DataSetProviderUtil method map.

/**
 * Applies the specified function to the specified field of the data set.
 */
@Nonnull
@SuppressWarnings("unchecked")
static DataFrame map(@Nonnull final DataFrame 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, (Seq<DataType>) Seq$.MODULE$.<DataType>empty());
    return dataSet.withColumn(fieldName, udf.apply(inputs));
}
Also used : UserDefinedFunction(org.apache.spark.sql.UserDefinedFunction) Column(org.apache.spark.sql.Column) DataType(org.apache.spark.sql.types.DataType) Nonnull(javax.annotation.Nonnull)

Example 2 with UserDefinedFunction

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

the class DataSetProviderUtilV1 method map.

/**
 * Applies the specified function to the specified field of the data set.
 */
@Nonnull
@SuppressWarnings("unchecked")
static DataFrame map(@Nonnull final DataFrame 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, (Seq<DataType>) Seq$.MODULE$.<DataType>empty());
    return dataSet.withColumn(fieldName, udf.apply(inputs));
}
Also used : UserDefinedFunction(org.apache.spark.sql.UserDefinedFunction) Column(org.apache.spark.sql.Column) DataType(org.apache.spark.sql.types.DataType) Nonnull(javax.annotation.Nonnull)

Aggregations

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