title: HIVE left join on nearest date
body: <p>I am trying to join 2 tables in HIVE using a key and the nearest date in the 2 tables at the time of join. For example: Below are the 2 input tables</p>
  
  <pre><code>&lt;----------TABLE A-------------&gt;            &lt;------------TABLE B------------&gt;
  A_id    A_date      changed_col             B_id    B_date      B_value A_id
  ****    ******      ***********             ****    ******      ******* *****   
  A01     2017-03-20      ABC                 B01     2017-04-02  200     A01
  A01     2017-04-01      XYZ                 B01     2017-04-04  500     A01
  A01     2017-04-05      LLL             
  </code></pre>
  
  <p>However when I LEFT JOIN table B with Table A, it should look for the nearest lowest date in table A for the same key(A_id). Below is the expected output table:    </p>
  
  <pre><code>B_id    B_date          A_id        A_date      changed col   B_value
  ****    ******          ****        ******      ***********   *******
  B01     2017-02-04      A01     2017-01-04      XYZ             200
  B01     2017-04-04      A01     2017-01-04      XYZ             500
  </code></pre>
  
  <p>Any help is much appreciated. Thanks</p>