问题描述
我一直在使用 Pig 和 XMLLOADER 来加载 xml 文件.我一直在练习 BOOK 示例.但是,我需要处理的 XML 文件在标签中有冒号.当我运行一个脚本时,它说由于 ':' 无法处理它.(最后是确切的日志)
Ive been using Pig and XMLLOADER to load xml files. I've been practising on BOOK example. However, XML file I need to process has colons in tag. When I run a script it says that due to ':' it cannot be processed.(exact log at the end)
这是我的文件.为:"大小写的目的而修改.BOOKT.xml
This is the file I have. Modified for the purpose of ":" case.BOOKT.xml
<CATALOG>
<BC:BOOK id="1">
<TITLE>Hadoop Defnitive Guide</TITLE>
<AUTHOR>Tom White</AUTHOR>
<COUNTRY>US</COUNTRY>
<COMPANY>CLOUDERA</COMPANY>
<PRICE>24.90</PRICE>
<YEAR>2012</YEAR>
</BC:BOOK>
<BOOK id="2">
<TITLE>Programming Pig</TITLE>
<AUTHOR>Alan Gates</AUTHOR>
<COUNTRY>USA</COUNTRY>
<COMPANY>Horton Works</COMPANY>
<PRICE>30.90</PRICE>
<YEAR>2013</YEAR>
</BOOK>
</CATALOG>
现在这是 BOOK.pig (注意:用正则表达式和 Xpath 尝试了这个,这就是为什么两者都出现并且错误仍然存在)
Now this is the BOOK.pig (note: tried this with regex and Xpath thats why both appear and error is still there)
REGISTER piggybank.jar
DEFINE XPath org.apache.pig.piggybank.evaluation.xml.XPath();
A = LOAD 'BOOKT' using org.apache.pig.piggybank.storage.XMLLoader('BC:BOOK') as (x:chararray);
dump A;
--B = foreach A GENERATE FLATTEN(REGEX_EXTRACT_ALL(x,'<BC:BOOK>\\s*<TITLE>(.*)</TITLE>\\s*<AUTHOR>(.*)</AUTHOR>\\s*<COUNTRY>(.*)</COUNTRY>\\s*<COMPANY>(.*)</COMPANY>\\s*<PRICE>(.*)</PRICE>\\s*<YEAR>(.*)</YEAR>\\s*</BC:BOOK>'));
B = FOREACH A GENERATE flatten XPath(x, 'BC:BOOK/AUTHOR'), XPath(x, 'BC:BOOK/PRICE');
describe B;
这是错误:
ERROR org.apache.pig.tools.pigstats.PigStats - ERROR 0:java.lang.RuntimeException: java.lang.RuntimeException: XML tag identifier 'BC:BOOK' does not match the regular expression /[a-zA-Z\_][0-9a-zA-Z\-_]+/
我的问题是我应该在 XMLLOADE(STRING identifier) 中放入什么,以便我可以使用带有:"的标签(我无法修改 piggybank.jar,我尝试将 : 作为 xml 特殊代码,我尝试使用 XMLLOADER('sth'+'sth')...
My question is what should i put in XMLLOADE(STRING identifier) so that I can have tags with ":" ( I cannot modify piggybank.jar, i tried putting : as a xml special code,and i tried using XMLLOADER('sth'+'sth')...
推荐答案
一个不太简洁的解决方案是将其加载到 pig 存储,然后将 ':' 替换为 '',然后使用 XMLLOADER 加载它.
One , not so neat solution, is to load it to pig storage and then to replace ':' with '', and then to load it with XMLLOADER.
这篇关于加载带有冒号的标签时出现猪 xmlloader 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!