Key Value pair combination. We are trying to explode the ID as a column name and VALUE as the corresponding data for each column.
`<CT> <items> <item> <field> <id>Column1</id> <value>25672</value> </field>
<field> <id>Column2</id> <value>FGE</value> </field> <field>
<id>Column3</id> <value>Florence to Venice</value> </field> </item>
</items>
</CT>`
We are expecting to create a table as below, Expected Output:
Column1 Column2 Column3
25672 FGE Florence to Venice
We tried using Map to extract the key value pair but we are not getting the desired result.
'CREATE EXTERNAL TABLE dev.reference_test(
PM_SubCollection array<map<string,string>>
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES(
"column.xpath.PM_SubCollection"="/CT/items/item/field",
"xml.map.specification.id"="#id->#value"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
LOCATION '/dev/reference_test'
TBLPROPERTIES (
"xmlinput.start"="",
"xmlinput.end"=""
);'
Output:
'[{"field":"Column125672"},{"field":"Column2FGE"},{"field":"Column3Florence to Venice"}]'
Any suggestions would be helpful