火花UDF的作品時,我做的show(),但它給了我的錯誤,當我做 filter的UDF結果。udf函數def chkInterPunctuation(sent) : for char in sent[1:-2] : if char in ["\"", "'", ".", "!", "?"] : return True return Falsecip = udf(chkInterPunctuation, BooleanType())show() 作品df_punct = dfs.withColumn("in_length", length("input")).\withColumn("out_length", length("output")).withColumn("cip", cip(col("input")))df_punct.show()但是當我這樣做時它給了我錯誤 filterdf_punct.where(col("cip") == True).show()我的谷歌搜索表明,py4j當UDF函數沒有返回正確的值或有錯誤時,通常會發生錯誤。但我UDF function總是返回 true 或 false。此外,當我顯示時,spark 查詢會返回正確的值。這對我來說沒有意義。可能的原因是什么?
3 回答

慕工程0101907
TA貢獻1887條經驗 獲得超5個贊
發生這種情況是因為您沒有糾正NULL存在。嘗試:
def chkInterPunctuation(sent) :
if not sent: return # In None return
for char in sent[1:-2] :
if char in ["\"", "'", ".", "!", "?"] :
return True
return False
添加回答
舉報
0/150
提交
取消