gpt4 book ai didi

xml - 可以将 HCatalog 与 XML 一起使用吗? -- 在 Cloudera VM 上执行 ETL

转载 作者:可可西里 更新时间:2023-11-01 15:06:25 26 4
gpt4 key购买 nike

我正在处理一个大数据类的项目,我已经在本地安装了 Cloudera Quickstart VM 以在我的数据集上运行一些基本任务并熟悉一些工具。我正在学习一个教程,其中涉及将数据集移动到 HDFS,基于数据集文件创建一个 HCatalog 表,然后在该表上运行 Hive 和/或 Pig 命令。问题是我的数据是一个大的 XML 文件,HCatalog 中的标准分隔符选项不适用。

有没有办法将 XML 导入 HCatalog?如果不是,在我的 XML 数据集上使用 Hive 或 Pig 的最佳方法是什么?

编辑:我的文件来自公共(public) StackOverflow 数据集。我正在使用 posts.xml 文件。它非常大 (25GB),我无法在我的机器上打开它,但下面是根据自述文件的结构:

- **posts**.xml
- Id
- PostTypeId
- 1: Question
- 2: Answer
- ParentID (only present if PostTypeId is 2)
- AcceptedAnswerId (only present if PostTypeId is 1)
- CreationDate
- Score
- ViewCount
- Body
- OwnerUserId
- LastEditorUserId
- LastEditorDisplayName="Jeff Atwood"
- LastEditDate="2009-03-05T22:28:34.823"
- LastActivityDate="2009-03-11T12:51:01.480"
- CommunityOwnedDate="2009-03-11T12:51:01.480"
- ClosedDate="2009-03-11T12:51:01.480"
- Title=
- Tags=
- AnswerCount
- CommentCount
- FavoriteCount

此文件的绝对大小是否会成为 VM 中的问题?最后,我们将在 AWS 中重复其中一些 ETL 任务,但现在我正努力避免在不知道如何正确使用某些工具的情况下支付大笔费用。

最佳答案

XML 使用相当标准化的结构,所以我很想知道您的数据格式以及什么分隔符不起作用。

在不了解更多关于数据/结构等的情况下......这可能是我会做的:

  1. 确定我的架构并手动创建 HCatalog(或脚本化,以最简单的为准)。
  2. 使用 piggybank XMLLoader 通过 pig 加载数据。
  3. 使用正则表达式将数据解析为我为 HCat 确定的模式
  4. 使用 HCatStore 方法存储它。



--示例代码

REGISTER piggybank.jar

items = LOAD 'rss.txt' USING org.apache.pig.piggybank.storage.XMLLoader('item') AS (item:chararray);

data = FOREACH items GENERATE
REGEX_EXTRACT(item, '<link>(.*)</link>', 1) AS link:chararray,
REGEX_EXTRACT(item, '<title>(.*)</title>', 1) AS title:chararray,
REGEX_EXTRACT(item, '<description>(.*)</description>', 1) AS description:chararray,
REGEX_EXTRACT(item, '<pubDate>.*(\\d{2}\\s[a-zA-Z]{3}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}).*</pubDate>', 1) AS pubdate:chararray;

STORE data into 'rss_items' USING org.apache.hcatalog.pig.HCatStorer();


validate = LOAD 'default.rss_items' USING org.apache.hcatalog.pig.HCatLoader();
dump validate;



-- 结果

(http://www.hannonhill.com/news/item1.html,News Item 1,Description of news item 1 here.,03 Jun 2003 09:39:21)
(http://www.hannonhill.com/news/item2.html,News Item 2,Description of news item 2 here.,30 May 2003 11:06:42)
(http://www.hannonhill.com/news/item3.html,News Item 3,Description of news item 3 here.,20 May 2003 08:56:02)



-- rss.txt 数据文件

<rss version="2.0">
<channel>
<title>News</title>
<link>http://www.hannonhill.com</link>
<description>Hannon Hill News</description>
<language>en-us</language>
<pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
<generator>Cascade Server</generator>
<webMaster>webmaster@hannonhill.com</webMaster>
<item>
<title>News Item 1</title>
<link>http://www.hannonhill.com/news/item1.html</link>
<description>Description of news item 1 here.</description>
<pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
<guid>http://www.hannonhill.com/news/item1.html</guid>
</item>
<item>
<title>News Item 2</title>
<link>http://www.hannonhill.com/news/item2.html</link>
<description>Description of news item 2 here.</description>
<pubDate>Fri, 30 May 2003 11:06:42 GMT</pubDate>
<guid>http://www.hannonhill.com/news/item2.html</guid>
</item>
<item>
<title>News Item 3</title>
<link>http://www.hannonhill.com/news/item3.html</link>
<description>Description of news item 3 here.</description>
<pubDate>Tue, 20 May 2003 08:56:02 GMT</pubDate>
<guid>http://www.hannonhill.com/news/item3.html</guid>
</item>
</channel>
</rss>

关于xml - 可以将 HCatalog 与 XML 一起使用吗? -- 在 Cloudera VM 上执行 ETL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22434300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com