hadoop - 尝试执行 Pig Latin 脚本时出现异常

标签 hadoop mapreduce apache-pig

我正在自学 Pig,在尝试探索数据集时遇到异常。脚本中有什么问题以及原因:

movies_data = LOAD '/movies_data' using PigStorage(',') as (id:chararray,title:chararray,year:int,rating:double,duration:double);
high   = FILTER movies_data by rating > 4.0;
high_rated = FOREACH high GENERATE movies_data.title,movies_data.year,movies_data.rating,movies_data.duration;
DUMP high_rated;

在 MAP Reduce 执行结束时,我收到以下错误。

2018-07-22 20:11:07,213 [main] ERROR org.apache.pig.tools.grunt.Grunt

ERROR 1066: Unable to open iterator for alias high_rated. 
Backend error : org.apache.pig.backend.executionengine.ExecException: 
ERROR 0: Scalar has more than one row in the output. 
1st : (1,The Nightmare Before Christmas,1993,3.9,4568.0), 
2nd :(2,The Mummy,1932,3.5,4388.0) 
(common cause: "JOIN" then "FOREACH ... GENERATE foo.bar" should be "foo::bar" )

最佳答案

首先,让我们看看如何解决您的问题。您不需要使用别名访问您的字段。你的第三行可以很简单:

high_rated = FOREACH high GENERATE title, year, rating, duration;

如果您出于某种原因想要使用别名,您应该使用引用运算符 (::),如错误建议中所示。然后你的行看起来像:

high_rated = FOREACH high GENERATE movies_data::title, movies_data::year, movies_data::rating, movies_data::duration;

接下来,让我们尝试了解错误消息背后的确切原因。当您尝试使用点运算符 (.) 访问字段时,pig 会假定别名是标量(别名只有一行)。由于您的别名不止一行,因此它会提示。您可以在此处阅读有关 Pig 中标量的更多信息:https://issues.apache.org/jira/browse/PIG-1434

在 JIRA 的发行说明部分,您会在末尾注意到,预期的错误消息与您收到的错误相匹配:

If a relation contains more than single tuple, a runtime error is generated: 
"Scalar has more than one row in the output"

关于hadoop - 尝试执行 Pig Latin 脚本时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51466235/

相关文章:

hadoop - Pig Latin 中的分组

sql - 配置单元分区,带通配符

java - 在hadoop中将文件作为单个记录读取

hadoop - 使用Pig脚本创建架构

hadoop - Pig脚本来压缩和解压缩bzip2中的hdfs数据

artificial-intelligence - 神经网络实现 MapReduce 风格

hadoop - 如何诊断无法在全局范围内找到 Kafka 主题

Scala mapreduce WordCount 程序

hadoop - hadoop集群中的各种端口?

mongodb - 在 mongodb 中转换集合的内存有效方法