首页 > 解决方案 > Pig 脚本错误:java.lang.Long 无法转换为 java.lang.Integer

问题描述

我为 Pig 运行以下代码片段:

publisher_hour_listings_cdf = foreach rscf_pub_hours_cumsum_proj generate
            rscf_publisher_id,
            rscf_is_uw,
            rscf_hour,
            (int)rscf_hour as rscf_hour_int,
            rscf_cum_listings,
            total_daily_listings,
            (rscf_cum_listings*1.0)/(total_daily_listings*1.0) as cdf,
            '$handledDate$';

我得到一个错误:

2020-05-02 04:31:53,130 信息 - [步骤] - 线程 74038 - /opt/pig/pig-0.17.0/bin/pig: [main] 错误 org.apache.pig.tools.pigstats.PigStats -错误 0:org.apache.pig.backend.executionengine.ExecException:错误 0:执行时出现异常(名称:publisher_hour_listings_cdf:New For Each(false,false,false,false,false,false,false,false)[bag] - scope-203 Operator Key: scope-203): org.apache.pig.backend.executionengine.ExecException: ERROR 0: Exception while execution [POCast (Name: Cast [long] - scope-171 Operator Key: scope-171) children : [[POProject (Name: Project[int][3] - scope-170 Operator Key: scope-170) children: null at []]] at [rscf_cum_listings[-1,-1]]]: java.lang. ClassCastException: java.lang.Long 不能转换为 java.lang.Integer

我们认为 Pig 未能将 Long 转换为 Integer。我们尝试使用“biginteger”而不是“int”进行转换:

        (biginteger)rscf_hour as rscf_hour_int

并且该脚本也因完全相同的错误消息而失败。

我们还尝试完全删除 int 强制转换:

    rscf_hour as rscf_hour_int

我们仍然得到同样的错误。

你知道为什么吗?

标签: apache-pig

解决方案


推荐阅读