读取 PIG 中的文件,其中 delemeter 包含数据

发布于 2025-01-02 11:50:03 字数 130 浏览 5 评论 0 原文

我想使用 PIG 读取 CSV 文件,我该怎么办?我使用了 load n pigstorage(',') 但它无法正确读取 CSV 文件,因为它在数据中遇到逗号 (,) 时会将其分割。如果数据中也有逗号,我现在应该如何给出 delimeter ?

I want to read a CSV file using PIG what should i Do?. I used load n pigstorage(',') but it fails to read CSV file properly because where it encounters comma (,) in data it splits it.How should i give delimeter now if i have comma in data also?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

家住魔仙堡 2025-01-09 11:50:03

通常无法区分数据中的逗号和作为分隔符的逗号。
您需要转义“数据”中的逗号以及可以识别转义逗号的自定义加载函数(对于 Pig)。

看看这里:
http://ofps.oreilly.com/titles/9781449302641/load_and_store_funcs.html
http://pig.apache.org/docs/r0 .7.0/udf.html#Load%2FStore+函数

It's generally impossible to distinguish comma in data from comma as a delimiter.
You will need to escape that comma that is in your 'data' and custom load function (for Pig) that can recognize escaped commas.

Take a look here:
http://ofps.oreilly.com/titles/9781449302641/load_and_store_funcs.html
http://pig.apache.org/docs/r0.7.0/udf.html#Load%2FStore+Functions

紫竹語嫣☆ 2025-01-09 11:50:03

您是否看过 加载器rel="nofollow">PiggyBank 如果你想读取 CSV 文件? (当然文件格式需要有效)

Have you had a look at the CSVLoader loader in the PiggyBank if you want to read a CSV file? (of course the file format needs to be valid)

初见你 2025-01-09 11:50:03

首先确保您有有效的 CSV 文件。如果您没有尝试通过 Excel(如果文件很小)或其他工具更改源文件,并导出带有良好数据分隔符的新 CSV(例如:\t 制表符、; 等)。更好的是可以使用“好”分隔符进行另一个提取。

您的负载示例可以是这样的:

TABLE = 使用 PigStorage(';') AS 加载 'input.csv' ( site_id: int,
名称:chararray,...);

您的转储示例:

使用 PigStorage(',') 将表存储到 'clean.csv' 中; <- 最适合您的分隔符

First make sure you have a valid CSV file. In the case you haven't try to change the source file through Excel (if the file is small) or other tool and export a new CSV with a good delimiter for your data (Ex: \t tab, ; , etc). Even better can be do another extract with a "good" delimiter.

Example of your load can be then something like this:

TABLE = LOAD 'input.csv' USING PigStorage(';') AS ( site_id: int,
name: chararray, ... );

Example of your DUMP:

STORE TABLE INTO 'clean.csv' using PigStorage(','); <- delimiter that suits you best

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文