How to insert row data between consecutive dates in HIVE?
select c.customer ,d.txn_date ,coalesce(t.tag,0) as tag from (select date_add (from_date,i) as txn_date from (select date '2017-01-01' as from_date ,date '2017-01-05' as to_date ) p lateral view posexplode(split(space(datediff(p.to_date,p.from_date)),' ')) pe as i,x ) d cross join (select distinct customer from t ) c left join t on t.customer = c.customer and t.txn_date = d.txn_date;
c.customer d.txn_date tagA 2017-01-01 1A 2017-01-02 1A 2017-01-03 0A 2017-01-04 1A 2017-01-05 0B 2017-01-01 0B 2017-01-02 0B 2017-01-03 1B 2017-01-04 0B 2017-01-05 0
Just have the delta content i.e the missing data in a file(input.txt) delimited with the same delimiter you have mentioned when you created the table.
Then use the load data command to insert this records into the table.
load data local inpath '/tmp/input.txt' into table tablename;
Your data wont be in the order you have mentioned , it would get appended to the last. You could retrieve the order by adding order by txn_date in the select query.