title: How to load hive table with map[structs] from another flat/simple hive table
body: <p>I have 2 tables in hive having Order's and Order_Detail's (having 1:n relation and joined on order_id) which I am trying to load to a single table taking advantage of hive complex data type - map[struct].</p>
  
  <p>Say ORDER has below data,</p>
  
  <p>Order_id total_amount customer</p>
  
  <p>123 10.00 1 </p>
  
  <p>456 12.00 2</p>
  
  <p>and ORDER_DETAILS have</p>
  
  <p>Order_id Order_Item_id Item_amount Item_type</p>
  
  <p>123 1 5.00 A</p>
  
  <p>123 2 5.00 B</p>
  
  <p>456 1 6.00 A</p>
  
  <p>456 2 3.00 B</p>
  
  <p>456 3 3.00 C</p>
  
  <p>I would like to create single table ORDERS with all order columns and order_detail columns as map of structs.
  This helps me to combine related data and query together thus avoiding frequent joins.
  I tried loading table with complex data types using txt/json files input with respective serde's and it works well.
  But in this scenario I want to load data from existing 2 hive tables of ORCFile format into the new table. Have tried some basic insert using named_struct function but it loads each row separately and does not combine same order_id's into a single row.</p>
  
  <p>Expected output something like ,</p>
  
  <p>123 10.00 1 [1:{5.00,A},2:{5.00,B}]</p>
  
  <p>456 12.00 2 {1:{6.00,A}, 2:{3.00,B},3:{3.00,C}]</p>
  
  <p>but i get ,</p>
  
  <p>123 10.00 1 [1:{5.00,A}]</p>
  
  <p>123 10.00 1 [2:{5.00,B}]</p>
  
  <p>456 12.00 2 {1:{6.00,A}]</p>
  
  <p>456 12.00 2 {2:{3.00,B}]</p>
  
  <p>456 12.00 2 {3:{3.00,C}]</p>
  
  <p>Kindly help me understand the way of achieving this with just INSERT INTO table select from 2 tables.
  Thanks in advance.</p>