When applying a Pyspark UDF that calls an AWS API, I get the error
PicklingError: Could not serialize object: TypeError: can't pickle SSLContext objects
The code is
import pyspark.sql.functions as sqlf
import boto3
comprehend = boto3.client('comprehend', region_name='us-east-1')
def detect_sentiment(text):
response = comprehend.detect_sentiment(Text=text, LanguageCode='pt')
return response["SentimentScore"]["Positive"]
detect_sentiment_udf = sqlf.udf(detect_sentiment)
test = df.withColumn("Positive", detect_sentiment_udf(df.Conversa))
Where df.Conversa
contains short simple strings.
Please, how can I solve this? Or what could be an alternative approach?