我正在尝试使用pig解析带有嵌套标记的xml文件。我有下面的xml示例。
<Document>
<medicationsInfo>
<code>10160-0</code>
<entryInfo>
<statusCode>completed</statusCode>
<startTime>20110729</startTime>
<endTime>20110822</endTime>
<strengthValue>24</strengthValue>
<strengthUnits>h</strengthUnits>
</entryInfo>
<entryInfo>
<statusCode>completed</statusCode>
<startTime>20120130</startTime>
<endTime>20120326</endTime>
<strengthValue>12</strengthValue>
<strengthUnits>h</strengthUnits>
</entryInfo>
<entryInfo>
<statusCode>completed</statusCode>
<startTime>20100412</startTime>
<endTime>20110822</endTime>
<strengthValue>8</strengthValue>
<strengthUnits>d</strengthUnits>
</entryInfo>
</medicationsInfo>
<ProductInfo>
<code>10160-0</code>
<entryInfo>
<statusCode>completed</statusCode>
<startTime>20110729</startTime>
<endTime>20110822</endTime>
<strengthValue>24</strengthValue>
<strengthUnits>h</strengthUnits>
</entryInfo>
<entryInfo>
<statusCode>completed</statusCode>
<startTime>20120130</startTime>
<endTime>20120326</endTime>
<strengthValue>12</strengthValue>
<strengthUnits>h</strengthUnits>
</entryInfo>
<entryInfo>
<statusCode>completed</statusCode>
<startTime>20100412</startTime>
<endTime>20110822</endTime>
<strengthValue>8</strengthValue>
<strengthUnits>d</strengthUnits>
</entryInfo>
</ProductInfo>
</Document>
我正在写下面的代码来获取药物结果的entryinfo信息,但是我得到了一个错误。
代码:
Register /home/cloudera/piggybank-0.16.0.jar;
DEFINE XPathAll org.apache.pig.piggybank.evaluation.xml.XPathAll();
DEFINE XPath org.apache.pig.piggybank.evaluation.xml.XPath();
A = LOAD '/home/cloudera/Parsed_CCD.xml' using org.apache.pig.piggybank.storage.XMLLoader('medicationsInfo/entryInfo') as (x:chararray);
B = FOREACH A GENERATE XPathAll(x, 'statusCode',false,true), XPathAll(x, 'medicationsInfo/code/code',false,true).$0, XPathAll(x,'strengthValue',false,true).$1;
DUMP B;
错误:
[main]info org.apache.pig.backend.hadoop.executionengine.mapreducelayer.mapreducelauncher-失败[main]error org.apache.pig.tools.grunt.grunt-错误1066:无法打开别名b的迭代器
预期产量:
completed 20110729 20110822 24 h
completed 20120130 20120326 12 h
completed 20100412 20110822 8 d
1条答案
按热度按时间sz81bmfz1#
以下代码将生成预期输出: