【问题标题】:Python UDF for Pig: datatype conversion errorPig的Python UDF:数据类型转换错误
【发布时间】:2012-10-02 02:07:07
【问题描述】:

我正在使用 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;

【问题讨论】:

  • A 的架构如何看起来像您迭代的?你用的是哪个 Pig 版本?
  • 我希望这是一个错字,但是您在 outputSchema 之前缺少 @ (即 @outputSchema("score:double") 。如果缺少,则不会调用装饰器,这意味着 Pig 不会知道输出是双倍的。

标签: hadoop user-defined-functions apache-pig


【解决方案1】:

正如@Ian Stevents 在 cmets 中指出的那样,这是因为您在装饰器中有错字。

你应该使用

@outputSchema("score:double")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-25
    • 2016-04-19
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    相关资源
    最近更新 更多