title: Joining multiple Spark Dataframes based on conditions
body: <p>Based on the "SC" code I need to join SRCTable with either RefTable-1 or RefTable-2</p>
  
  <p>Condition:
  If SC is "D" , SRCTable join with RefTable-1 on KEY = KEY1, to get the value.
  Else IF SC is "U" , SRCTable join with RefTable-2 on KEY = KEY2 &amp; FK = KEY3 , to get the value.</p>
  
  <p>This is the input spark dataframe.</p>
  
  <pre><code>SRCTable:
      -------------
      KEY |SC  |FK 
      -------------
      66  |D   | a
      67  |U   | b
      70  |D   | y
      71  |U   | q
      -------------
   RefTable-1:
      --------------
      KEY1 |Value  | 
      --------------
      66   |xyz1   | 
      67   |abc1   | 
      68   |fgr1   |
      69   |yte1   |
      70   |erx1   |
      71   |ter1   |
      --------------
   RefTable-2:
      --------------------
      KEY2 |KEY3  |Value  | 
      --------------------
      66   | a    |xyz2   | 
      67   | c    |abc2   | 
      67   | b    |fgr2   |
      69   | g    |yte2   |
      70   | y    |erx2   |
      71   | q    |ter2   |
      --------------------
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code>    --------------------
      KEY |SC  |FK |Value |
      -------------------- 
      66  |D   | a |xyz1  |
      67  |U   | b |fgr2  |
      70  |D   | y |erx1  |
      71  |U   | q |ter2  |
      ---------------------
  </code></pre>
  
  <p>Note: The Input tables will have millions of records, so need an optimized solution </p>