zeugederunity
09/30/2020, 8:00 AMIlya Muradyan
09/30/2020, 11:00 AMPasha Finkelshteyn
09/30/2020, 11:03 AMzeugederunity
09/30/2020, 11:09 AMPasha Finkelshteyn
09/30/2020, 11:14 AMzeugederunity
10/05/2020, 10:31 AMUDFRegistration::register
to place the parameter functional interface at the end of the parameters. Furthermore i added some typeckecks while calling the register function, to make sure that the parameters of the UDF<N>
funtion are not sublasses of kotlin.collections.Iterable or any type of array (this causes errors). I also added a class to wrap this whole functions.callUDF
with more security checks. Now creating and calling an UDF looks like this in my code:
val joinArray = spark.sqlContext()
.udf()
.register("joinArray", DataTypes.StringType) {
array: WrappedArray<String> ->
array.asMutableCollection().joinToString(" ")
}
val processedResult = result.withColumn("colName", joinArray(result.col("colName")))
Another point:
A function like this for WrappedArray
-instances would be nice in the framework:
fun <T> WrappedArray<T>.asMutableCollection(): MutableCollection<T> =
JavaConverters.asJavaCollectionConverter(this).asJavaCollection()
Because it took me pretty long to find out, that there is this converter-function.
Especially when the error message only says, that the conversion to a List
ist not possible it is quite hard for someone new to Spark and Scala to figure out what is going wrong.Pasha Finkelshteyn
10/05/2020, 10:32 AMPasha Finkelshteyn
10/05/2020, 10:33 AMzeugederunity
10/05/2020, 10:33 AMPasha Finkelshteyn
10/05/2020, 10:34 AMUDFRegistration
?Pasha Finkelshteyn
10/05/2020, 10:34 AMWrappedArray
?zeugederunity
10/05/2020, 10:36 AMPasha Finkelshteyn
10/05/2020, 10:37 AMPasha Finkelshteyn
10/05/2020, 10:38 AMzeugederunity
10/05/2020, 10:39 AMPasha Finkelshteyn
10/05/2020, 10:39 AMPasha Finkelshteyn
10/05/2020, 10:39 AMzeugederunity
10/05/2020, 11:13 AMCannot resolve org.jetbrains.kotlinx.spark:kotlin-spark-api-2.4_2.11:1.0.0-preview2-SNAPSHOT
for Kotlin Spark API: Examples for Spark 2.4+ (Scala 2.11)
Pasha Finkelshteyn
10/05/2020, 11:14 AMPasha Finkelshteyn
10/05/2020, 11:14 AMPasha Finkelshteyn
10/05/2020, 11:15 AMscala-2.11
Pasha Finkelshteyn
10/05/2020, 11:15 AMzeugederunity
10/05/2020, 11:18 AMzeugederunity
10/05/2020, 2:07 PMzeugederunity
10/05/2020, 2:08 PMzeugederunity
10/05/2020, 2:11 PM