I have a HIVE table in which data is loaded for tripid as tripid, gps_location_1, gps_location_2 locations, it could be 10 gps locations for one trip and for other trip there could be 500 gps locations, when I query data my results are as follows
select tripid, size(gps) as count from trip;
tripid gps_location_1 |gps_location_2 | count |
1451f2b3d |44.1145 | 44.1148| 9 |
select tripid, gps.gps_location_1, gps.gps_location_1 as count from trip;
+---------+-----------------------------------------------------------+----------------------------------------------------------+
tripid | gps_location_1 | gps_location_2 | count |
+---------+-------------------------------------------------------------+----------------------------------------------------------+ 1451f2b3d |[44.1145,44.1146,44.1147,44.1148,44.1148,44.1129,44.1127,44.1121] | [44.1148,44.1146,44.1146,44.1141,44.1138,44.1129,44.1127]| 9 | +---------+------------------------------------------------------------------+----------------------------------------------------------+
I can see first value from trip array table.
select tripid, gps[0].gps_location_1, gps[0].gps_location_1 from trip;
tripid gps_location_1 gps_location_2
1451f2b3d 44.1145 44.1148
2nd row from trip array table
select tripid, gps[1].gps_location_1, gps[1].gps_location_1 from trip;
tripid gps_location_1 gps_location_2
1451f2b3d 44.1146 44.1146
Last row from trip array table
select tripid, gps[size(gps)].gps_location_1, gps[size(gps)].gps_location_1 from trip;
1451f2b3d 44.1121 44.1127
I need to store each row in my new target_trip table like this, loop through all rows for one tripid in trip table and inserted into target_table showing below.
How can I achieve it?
tripid gps_location_1 gps_location_2
1451f2b3d 44.1145 44.1148
1451f2b3d 44.1146 44.1146
1451f2b3d 44.1147 44.1146
1451f2b3d 44.1148 44.1141
1451f2b3d 44.1129 44.1138
1451f2b3d 44.1127 44.1129
1451f2b3d 44.1121 44.1127