title: Dynamically select multiple columns while joining different Dataframe in Scala Spark
body: <p>I have two spark data frame <code>df1</code> and <code>df2</code>. Is there a way for selecting output columns dynamically while joining these two dataframes? The below definition outputs all column from df1 and df2 in case of inner join. </p>
  
  <pre><code>def joinDF (df1: DataFrame,  df2: DataFrame , joinExprs: Column, joinType: String): DataFrame = {   
    val dfJoinResult = df1.join(df2, joinExprs, joinType)
    dfJoinResult
    //.select()
  }
  </code></pre>
  
  <p>Input data:</p>
  
  <pre><code>val df1 = List(("1","new","current"), ("2","closed","saving"), ("3","blocked","credit")).toDF("id","type","account")
  val df2 = List(("1","7"), ("2","5"), ("5","8")).toDF("id","value")
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>val dfJoinResult = df1
    .join(df2, df1("id") === df2("id"), "inner")
    .select(df1("type"), df1("account"), df2("value")) 
  </code></pre>
  
  <p>dfJoinResult.schema(): </p>
  
  <pre><code>StructType(StructField(type,StringType,true), 
  StructField(account,StringType,true), 
  StructField(value,StringType,true))
  </code></pre>
  
  <p>I have looked at options like <code>df.select(cols.head, cols.tail: _*)</code>  but it does not allow to select columns from both DF's.
  Is there a way to pass <code>selectExpr</code> columns dynamically along with dataframe details that we want to select it from in my <code>def</code>? I'm using Spark 2.2.0.</p>