在 Pig 中提取 CSV 文件的第一行 [英] Extract first line of CSV file in Pig
问题描述
我有几个 CSV 文件,标题始终是文件中的第一行.将那行作为 Pig 中的字符串从 CSV 文件中取出的最佳方法是什么?不能使用 sed、awk 等进行预处理.
I have several CSV files and the header is always the first line in the file. What's the best way to get that line out of the CSV file as a string in Pig? Preprocessing with sed, awk etc is not an option.
我已经尝试使用常规 PigStorage 和 Piggy bank CsvLoader 加载文件,但我不清楚如何获得第一行(如果有的话).
I've tried loading the file with regular PigStorage and the Piggy bank CsvLoader, but its not clear to me how I can get that first line, if at all.
如果需要,我愿意编写 UDF.
I'm open to writing an UDF, if that's what it takes.
推荐答案
如果您的 CSV 符合 Excel 2007 的 CSV 约定,您可以使用来自 Piggybank 的现有加载程序 http://svn.apache.org/viewvc/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/CSVExcelStorage.java?view=markup
If your CSV comply with CSV conventions of Excel 2007 you can use already available loader from Piggybank http://svn.apache.org/viewvc/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/CSVExcelStorage.java?view=markup
它可以选择跳过 CSV 标头 SKIP_INPUT_HEADER
It has an option to skip the CSV header SKIP_INPUT_HEADER
这篇关于在 Pig 中提取 CSV 文件的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!