【问题标题】:Pig flatten error猪压扁错误
【发布时间】:2023-04-03 01:00:01
【问题描述】:

我为我的嵌套数据尝试了这个脚本:

 `books = load 'data/book-seded-workings-reduced.json'
    using JsonLoader('user_id:chararray,type:chararray,title:chararray,year:chararray,publisher:chararray,authors:{(name:chararray)},source:chararray');`

group_auth = group books by title;

maped = foreach group_auth generate group, books.authors;

fil = foreach maped generate flatten(books); DUMP fil;

但我收到此错误:需要从关系中投影一列才能用作标量

有什么想法吗?

【问题讨论】:

  • 您能解释一下您要解决的问题吗?如果您不使用任何聚合操作,为什么要按标题对“书籍”进行分组,然后生成书籍的组、作者并将其展平?您只能使用 foreach generate 语句来执行此操作。
  • 你可以在这里看到我的数据:stackoverflow.com/questions/24976373/…我正在尝试为每个标题生成,但与他相关联的作者却一个一个...稍后我想对作者进行查询(我的脚本中的“名称”字段)所以我认为我必须使用 flatten 删除嵌套结构
  • 我也尝试使用 hive 进行此类查询,但我仍然遇到我的 serde 错误:stackoverflow.com/questions/25149700/… 所以我对 Hive 和 Pig 有点困惑
  • 在这种情况下,您可以删除 group by 子句。在 load 语句后尝试下面的代码: flatten_authors = foreach books generate title, FLATTEN(authors.name);

标签: hadoop apache-pig flatten cloudera-cdh


【解决方案1】:
books = load 'input.data'
    using JsonLoader('user_id:chararray,
                      type:chararray,
                      title:chararray,
                      year:chararray,
                      publisher:chararray,
                      authors:{(name:chararray)},source:chararray');

flatten_authors = foreach books generate title, FLATTEN(authors.name);

dump flatten_authors;

输出:(来自Loading JSON file with serde in Cloudera的输入)

(Modern Database Systems: The Object Model, Interoperability, and Beyond.,null)
(Inequalities: Theory of Majorization and Its Application.,Albert W. Marshall)
(Inequalities: Theory of Majorization and Its Application.,Ingram Olkin)

【讨论】:

  • 不知道。让我试试,如果能解决,我会发布我的答案!
猜你喜欢
  • 1970-01-01
  • 2015-01-15
  • 2016-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-11
  • 1970-01-01
相关资源
最近更新 更多