variables equal with doublemetaphone on pyspark

177 views Asked by At

I want to use the fonction **"doublemetaphone"** on my data set on **pyspark**.
The expectation result is a boolean: TRUE or FALSE.
But *@udf("bool")* doesn't work, is there another way?
from metaphone import doublemetaphone

@udf("bool") 
def udf_doublemetaphone(a,b):
  return doublemetaphone(a)== doublemetaphone(b)

data_set_doublemetaphone = (data_set.withColumn("doublemetaphone", 
                                                   udf_doublemetaphone(col("A"),col("B")))) ```
1

There are 1 answers

0
Neoooar On

I have find!
This is @udf(BooleanType())
So you can use like this: rom metaphone import doublemetaphone

@udf(BooleanType()) 
def udf_doublemetaphone(a,b):
 return doublemetaphone(a)== doublemetaphone(b)

data_set_doublemetaphone = (data_set.withColumn("doublemetaphone", 
                                                  udf_doublemetaphone(col("A"),col("B")))) ```