Boolea" /> Boolea" /> Boolea"/>

UDF in Spark 1.6 Reassignment to val error

99 Views Asked by At

I am using Spark 1.6

The below udf is used to clean address data.

sqlContext.udf.register("cleanaddress", (AD1:String,AD2: String, AD3:String)=>Boolean = _.matches("^[a-zA-Z0-9]*$"))

UDF Name : cleanaddress Three input parameter is coming from DataFrame column,(AD1,AD2 and AD3).

May someone please help me to fix the below error.

i am trying to write udf which accept three parameter (3 address column of dataframe), compute and give only the filter records.

Error:
Error:(38, 91) reassignment to val
    sqlContext.udf.register("cleanaddress", (AD1:String, AD2: String, AD3:String)=>Boolean = _.matches("^[a-zA-Z0-9]*$"))
1

There are 1 best solutions below

1
Raphael Roth On BEST ANSWER

Your logic is not quite clear fro your given code. What you can do is to return an array of valid addresses like this:

sqlContext.udf.register("cleanaddress", (AD1:String, AD2: String, AD3:String)=> Seq(AD1,AD2,AD3).filter(_.matches("^[a-zA-Z0-9]*$")))

Note that this will return a complex column (i.e. an array)