我正在使用 Python UDF,它在减少阶段会导致错误。
java.lang.ClassCastException: java.lang.Double cannot be cast to org.apache.pig.data.DataByteArray
这是 UDF 的代码:
import math
outputSchema("score:double")
def confidenceLowerBound(numerator, denominator, constant):
raw_score = numerator * 1.0 / denominator
normalized_interval = math.sqrt( raw_score * (1 - raw_score) / denominator )
wilson_score = raw_score - constant * normalized_interval
return wilson_score
这就是我在 pig 中调用 udf 的方式。
register 'confidence_interval_compute.py' using jython as pyutils;
...
..
A = FOREACH A GENERATE $0, $1, $2, $3, $4, pyutils.confidenceLowerBound($3, $4, 4) AS score PARALLEL 20;