应用调用 AWS API 的 Pyspark UDF 时,出现错误
PicklingError: Could not serialize object: TypeError: can't pickle SSLContext objects
代码是
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))
其中df.Conversa
包含简短的简单字符串。请问,我该如何解决这个问题?或者有什么替代方法?