Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to execute user defined function(VectorAssembler

I am working with a Kmeans as clustering algorithme, my code want execute and showing me this error:

org.apache.spark.SparkException: Failed to execute user defined function(VectorAssembler$$Lambda$1525/671078904: (struct<latitude:double,longitude:double>) => struct<type:tinyint,size:int,indices:array<int>,values:array<double>>)
    at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown Source)

here is the dataframe code:

val st = stations
    .withColumn("longitude", $"longitude".cast(sql.types.DoubleType))
    .withColumn("latitude", $"latitude".cast(sql.types.DoubleType))
val stationVA = new VectorAssembler()
    .setInputCols(Array("latitude","longitude"))
    .setOutputCol("location")
val stationWithLoc =stationVA.transform(st)

println("Assembled columns 'hour', 'mobile', 'userFeatures' to vector column 'location'")
stationWithLoc.select("name", "position").show(false)

stationWithLoc.printSchema()
stationWithLoc.show()

for the Schema it work but in case if I put the show I am getting the issue.

like image 524
Aymen Rahal Avatar asked Jul 15 '26 03:07

Aymen Rahal


1 Answers

This question is old, but I just ran into this issue with pyspark.

I believe the error is related to null values in the data. Doing a fillna() on my columns before using VectorAssembler resolved the error.

like image 185
trianta2 Avatar answered Jul 17 '26 15:07

trianta2