读取 PIG 中的文件,其中 delemeter 包含数据
我想使用 PIG 读取 CSV 文件,我该怎么办?我使用了 load n pigstorage(',') 但它无法正确读取 CSV 文件,因为它在数据中遇到逗号 (,) 时会将其分割。如果数据中也有逗号,我现在应该如何给出 delimeter ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常无法区分数据中的逗号和作为分隔符的逗号。
您需要转义“数据”中的逗号以及可以识别转义逗号的自定义加载函数(对于 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
您是否看过 加载器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)
首先确保您有有效的 CSV 文件。如果您没有尝试通过 Excel(如果文件很小)或其他工具更改源文件,并导出带有良好数据分隔符的新 CSV(例如:\t 制表符、; 等)。更好的是可以使用“好”分隔符进行另一个提取。
您的负载示例可以是这样的:
您的转储示例:
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:
Example of your DUMP: