I can't see anything wrong here.
Initially you are outer joining foo with bar for status_bar = a
here you will get output as
key, status_foo, val, status_bar
1, b, qwerty, -
2, b, asdf, a
4, - - a
Now you are Left joining foo (above resultant table) with bar
so the join will take care wrt key field (key&status_bar) and not only key field as foo table has now status_bar field also
so when you are doing left join you don't have 3 & b so you will not get data for 3 and b !
Peter, your left join happending on both key & status_bar that leads to wrong results. Please find the below script.
LOAD key , status_bar Resident bar where status_bar = 'a' ;
Left Join (foo)
LOAD key , status_bar as temp_bar_b Resident bar where status_bar = 'b' ;
DROP Table bar;
LOAD key , val , status_foo , if(IsNull(status_bar) , temp_bar_b , status_bar ) as status_bar Resident foo;
DROP Table foo;