Ошибка при загрузке таблицы куста с помощью Hcatalog в Pig

Я пытаюсь загрузить свою таблицу кустов, используя Hcatalog в свинье, для этого я написал код ниже, но получаю сообщение об ошибке. Я открываю свою свиную оболочку, используя pig -useHCatalog

Код:

A = LOAD 'patient_info' USING org.apache.hive.hcatalog.pig.HCatLoader();

Ошибка:

Обновление:

Моя команда для хранения данных в улье приведена ниже.

Образец:

add jar /home/cloudera/hivexmlserde-1.0.5.3.jar;
CREATE EXTERNAL TABLE patient_info (
statusCode string,
title string,
startTime string,
endTime string,
frequencyValue string,
frequencyUnits string

)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES (
"column.xpath.statusCode"="medicationsInfo/entryInfo/statusCode/text()",
"column.xpath.title"="medications/code/code/text()",
"column.xpath.startTime"="medications/xxx/startTime/text()",
"column.xpath.endTime"="medications/xxx/endTime/text()",
"column.xpath.frequencyValue"="medications/xxx/frequencyValue/text()",
"column.xpath.frequencyUnits"="medications/xxx/frequencyUnits/text()",
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
TBLPROPERTIES (
"xmlinput.start"="<medicationsInfo",
"xmlinput.end"="</medicationsInfo>");


load data inpath '/user/cloudera/xml' into table patient_info ;

Недопустимое определение вашей внешней таблицы. Вот несколько вариантов:

 <Document>
    <ProductCode>
     <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> 
    </ProductCode>
    <ProductCode>
     <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> 
    </ProductCode> 
   <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>
    <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> 
    </Document>

person animal    schedule 14.02.2017    source источник
comment
Я попытался получить данные из улья, и я могу их получить.   -  person 54l3d    schedule 14.02.2017
comment
Можете ли вы добавить определение таблицы к своему вопросу, пожалуйста?   -  person animal    schedule 14.02.2017
comment
Похоже, что XmlSerDe не известен свиньям. Хотите поделиться, как вы сохранили данные?   -  person 54l3d    schedule 14.02.2017
comment
@DuduMarkovitz Я сохранил свои данные, используя свинью для анализа файла в hdfs, а затем использовал команду создания улья для хранения проанализированных данных в улье.   -  person David דודו Markovitz    schedule 14.02.2017
comment
Пожалуйста, будьте более конкретными. Я понимаю, что вы загрузили данные и обработали их с помощью PIG, но я не понимаю, что произошло позже. Также поделитесь соответствующей командой (не обработка, а загрузка и хранение данных в PIG/Hive)   -  person animal    schedule 15.02.2017
comment
@DuduMarkovitz Я обновил свой вопрос, пожалуйста, проверьте.   -  person David דודו Markovitz    schedule 15.02.2017
comment
Это не имеет смысла... откуда взялась ошибка на _1_?   -  person animal    schedule 15.02.2017
comment
Но похоже, что вы пытаетесь прочитать файл, который был сохранен с помощью XmlSerDe , используя PIG.   -  person David דודו Markovitz    schedule 15.02.2017
comment
@DuduMarkovitz, извини, я дал тебе неправильное объяснение. Я использую hivexmlserde для хранения данных в улье.   -  person David דודו Markovitz    schedule 15.02.2017
comment
@DuduMarkovitz, пожалуйста, помогите мне.   -  person animal    schedule 15.02.2017
comment
Это все еще не имеет смысла. Таблица, которую вы пытаетесь загрузить с помощью PIG, называется patient_info, а таблица куста — medica.   -  person animal    schedule 15.02.2017
comment
Также _1_ к лекарству не имеет смысла. Все, что вам нужно сделать, это определить _2_ для внешней таблицы.   -  person David דודו Markovitz    schedule 15.02.2017
comment
я добавил load data просто фактический код имеет location '/user/cloudera/xml' я следовал тому, что вы сказали, но появляется та же ошибка. Это потому что я использую _3_   -  person David דודו Markovitz    schedule 15.02.2017
comment
не могли бы вы добавить небольшой образец данных?   -  person animal    schedule 15.02.2017
comment
Образец @DuduMarkovitz, который я не могу опубликовать, так как моя компания имеет конфиденциальные данные.   -  person David דודו Markovitz    schedule 15.02.2017
comment
Реальные данные не важны, важна только структура. Просто замените реальные данные на тарабарщину.   -  person animal    schedule 15.02.2017
comment
@DuduMarkovitz, я обновил свой вопрос, пожалуйста, проверьте. Фактические данные имеют огромные вложенные теги, которые я не могу привести здесь. Вот его образец.   -  person David דודו Markovitz    schedule 15.02.2017
comment
То, что вы пытаетесь сделать, недопустимо, поскольку у вас есть несколько entryInfo для каждого лекарства. Вы можете разорвать XML на записьInfo (но тогда вы используете информацию о лекарствах, например, код), или вы можете разбить его на информацию о лекарствах, но тогда вам нужно взять entryInfo как целый фрагмент xml (не разбивая его на поля)   -  person animal    schedule 15.02.2017
comment
мне нужны мои результаты в формате столбцов, но в этих случаях я получаю свои результаты в одной строке. Как я могу выбрать конкретное значение прочности, которое мне нужно. Если вы, пожалуйста, помогите мне с этим.   -  person David דודו Markovitz    schedule 15.02.2017


Ответы (1)


Опция 1


Вариант 2

create external table patient_info 
(
    code        string
   ,entryInfo   string
)
row format serde 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
with serdeproperties 
(
    "column.xpath.code"      = "/Medicationsinfo/code/text()"
   ,"column.xpath.entryInfo" = "/Medicationsinfo/entryInfo"
)
stored as
inputformat 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
location '/user/hive/warehouse/patient_info'
tblproperties 
(
    "xmlinput.start" = "<Medicationsinfo"
   ,"xmlinput.end"   = "</Medicationsinfo>"
)
;

select * from patient_info
;

+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| patient_info.code | patient_info.entryinfo                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 10160-0           | <string><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></string> |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 10160-0           | <string><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></string> |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Вариант 3

create external table patient_info 
(
    code        string
   ,entryInfo   array<map<string,map<string,string>>>
)
row format serde 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
with serdeproperties 
(
    "column.xpath.code"      = "/Medicationsinfo/code/text()"
   ,"column.xpath.entryInfo" = "/Medicationsinfo/entryInfo"
)
stored as
inputformat 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
location '/user/hive/warehouse/patient_info'
tblproperties 
(
    "xmlinput.start" = "<Medicationsinfo"
   ,"xmlinput.end"   = "</Medicationsinfo>"
)
;

select * from patient_info
;

+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| patient_info.code |                                                                                                                                                                                   patient_info.entryinfo                                                                                                                                                                                   |
+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 10160-0           | [{"entryInfo":{"statusCode":"completed","startTime":"20110729","strengthUnits":"h","endTime":"20110822","strengthValue":"24"}},{"entryInfo":{"statusCode":"completed","startTime":"20120130","strengthUnits":"h","endTime":"20120326","strengthValue":"12"}},{"entryInfo":{"statusCode":"completed","startTime":"20100412","strengthUnits":"d","endTime":"20110822","strengthValue":"8"}}] |
| 10160-0           | [{"entryInfo":{"statusCode":"completed","startTime":"20110729","strengthUnits":"h","endTime":"20110822","strengthValue":"24"}},{"entryInfo":{"statusCode":"completed","startTime":"20120130","strengthUnits":"h","endTime":"20120326","strengthValue":"12"}},{"entryInfo":{"statusCode":"completed","startTime":"20100412","strengthUnits":"d","endTime":"20110822","strengthValue":"8"}}] |
+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Взорвать вариант 3

create external table patient_info 
(
    code        string
   ,entryInfo   array<map<string,struct<statusCode:string,startTime:string,endTime:string,strengthValue:int,strengthUnits:string>>>
)
row format serde 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
with serdeproperties 
(
    "column.xpath.code"      = "/Medicationsinfo/code/text()"
   ,"column.xpath.entryInfo" = "/Medicationsinfo/entryInfo"
)
stored as
inputformat 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
location '/user/hive/warehouse/patient_info'
tblproperties 
(
    "xmlinput.start" = "<Medicationsinfo"
   ,"xmlinput.end"   = "</Medicationsinfo>"
)
;

select * from patient_info
;

+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| patient_info.code |                                                                                                                                                                                patient_info.entryinfo                                                                                                                                                                                |
+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 10160-0           | [{"entryInfo":{"statuscode":"completed","starttime":"20110729","endtime":"20110822","strengthvalue":24,"strengthunits":"h"}},{"entryInfo":{"statuscode":"completed","starttime":"20120130","endtime":"20120326","strengthvalue":12,"strengthunits":"h"}},{"entryInfo":{"statuscode":"completed","starttime":"20100412","endtime":"20110822","strengthvalue":8,"strengthunits":"d"}}] |
| 10160-0           | [{"entryInfo":{"statuscode":"completed","starttime":"20110729","endtime":"20110822","strengthvalue":24,"strengthunits":"h"}},{"entryInfo":{"statuscode":"completed","starttime":"20120130","endtime":"20120326","strengthvalue":12,"strengthunits":"h"}},{"entryInfo":{"statuscode":"completed","starttime":"20100412","endtime":"20110822","strengthvalue":8,"strengthunits":"d"}}] |
+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Это похоже на ошибку, попробуйте выбрать несколько строк из вашей таблицы в улье для проверки.

select  pi.code
       ,ei.i + 1    as i
       ,ei.entryInfo["entryInfo"].statusCode
       ,ei.entryInfo["entryInfo"].startTime
       ,ei.entryInfo["entryInfo"].endTime
       ,ei.entryInfo["entryInfo"].strengthValue
       ,ei.entryInfo["entryInfo"].strengthUnits

from    patient_info    pi
        lateral view  posexplode (entryInfo) ei as i,entryInfo
;

+---------+---+------------+-----------+----------+---------------+---------------+
| pi.code | i | statuscode | starttime | endtime  | strengthvalue | strengthunits |
+---------+---+------------+-----------+----------+---------------+---------------+
| 10160-0 | 1 | completed  | 20110729  | 20110822 | 24            | h             |
+---------+---+------------+-----------+----------+---------------+---------------+
| 10160-0 | 2 | completed  | 20120130  | 20120326 | 12            | h             |
+---------+---+------------+-----------+----------+---------------+---------------+
| 10160-0 | 3 | completed  | 20100412  | 20110822 | 8             | d             |
+---------+---+------------+-----------+----------+---------------+---------------+
| 10160-0 | 1 | completed  | 20110729  | 20110822 | 24            | h             |
+---------+---+------------+-----------+----------+---------------+---------------+
| 10160-0 | 2 | completed  | 20120130  | 20120326 | 12            | h             |
+---------+---+------------+-----------+----------+---------------+---------------+
| 10160-0 | 3 | completed  | 20100412  | 20110822 | 8             | d             |
+---------+---+------------+-----------+----------+---------------+---------------+
person David דודו Markovitz    schedule 15.02.2017
comment
Спасибо. Я жду этого. Я принимаю ваш ответ, вы мне очень помогли. - person animal; 15.02.2017
comment
можете ли вы объяснить мне, почему вы использовали _1_ - person animal; 15.02.2017
comment
posexplode начинается с 0, и я подумал, что было бы более удобочитаемо видеть последовательность 1,2,3,... над 0,1,2... - person animal; 16.02.2017
comment
Понял, спасибо за быстрый ответ. - person David דודו Markovitz; 16.02.2017
comment
ОШИБКА hive.ql.metadata.Table - невозможно получить поле из serde: com.ibm.spss.hive.serde2.xml.XmlSerDe java.lang.RuntimeException: MetaException (сообщение: java.lang.ClassNotFoundException Class com.ibm.spss .hive.serde2.xml.XmlSerDe не найден) в org.apache.hadoop.hive.ql.metadata.Table.getDeserializerFromMetaStore(Table.java:275) в org.apache.hadoop.hive.ql.metadata.Table.getDeserializer (Table.java:255) в org.apache.hadoop.hive.ql.metadata.Table.getCols(Table.java:602) в org.apache.hive.hcatalog.common.HCatUtil.getTableSchemaWithPtnCols(HCatUtil.java:184) ) в org.apache.hive.hcatalog.pig.HCatLoader.getSchema(HCatLoader.java:216) в org.apache.pig.newplan.logical.relational.LOLoad.getSchemaFromMetaData(LOLoad.java:175) в org.apache. pig.newplan.logical.relational.LOLoad.(LOLoad.java:89) в org.apache.pig.parser.LogicalPlanBuilder.buildLoadOp(LogicalPlanBuilder.java:866) в org.apache.pig.parser.LogicalPlanGenerator.load_clause(Logical PlanGenerator.java:3568) в org.apache.pig.parser.LogicalPlanGenerator.op_clause(LogicalPlanGenerator.java:1625) в org.apache.pig.parser.LogicalPlanGenerator.general_statement(LogicalPlanGenerator.java:1102) в org.apache.pig .parser.LogicalPlanGenerator.statement(LogicalPlanGenerator.java:560) в org.apache.pig.parser.LogicalPlanGenerator.query(LogicalPlanGenerator.java:421) в org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:188) ) в org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1688) в org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1635) в org.apache.pig.PigServer.registerQuery( PigServer.java:587) в org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:1093) в org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:501) в org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:198) в org.apache.pig.tools.grunt.Grun tParser.parseStopOnError(GruntParser.java:173) в org.apache.pig.tools.grunt.Grunt.run(Grunt.java:69) в org.apache.pig.Main.run(Main.java:547) в org .apache.pig.Main.main(Main.java:158) в sun.reflect.NativeMethodAccessorImpl.invoke0(собственный метод) в sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) в sun.reflect.DelegatingMethodAccessorImpl.invoke (ДелегированиеMethodAccessorImpl.java:43) на java.lang.reflect. Method.invoke(Method.java:606) в org.apache.hadoop.util.RunJar.run(RunJar.java:221) в org.apache.hadoop.util.RunJar.main(RunJar.java:136) Вызвано : MetaException (сообщение: java.lang.ClassNotFoundException Class com.ibm.spss.hive.serde2.xml.XmlSerDe не найден) в org.apache.hadoop.hive.metastore.MetaStoreUtils.getDeserializer(MetaStoreUtils.java:400) - person animal; 16.02.2017