title: Conditional Join in Spark DataFrame
body: <p>I am trying to join two <code>DataFrame</code> with condition.</p>
  
  <p>I have two dataframe A and B.</p>
  
  <p>A contains id,m_cd and c_cd columns
  B contains m_cd,c_cd and record columns</p>
  
  <p>Conditions are -</p>
  
  <ul>
  <li>If m_cd is null then join c_cd of A with B</li>
  <li>If m_cd is not null then join m_cd of A with B</li>
  </ul>
  
  <p>we can use "<code>when</code>" and "<code>otherwise</code>()" in <code>withcolumn</code>() method of dataframe, so is there any way to do this for the case of join in dataframe.</p>
  
  <p>I have already done this using <code>Union</code>.But wanted to know if there any other option available.</p>