title: Dynamically creating dataframes in Spark Scala
body: <p>I have few columns data coming out of a Dataframe 1, in a loop (from different rows). I want to create a Dataframe 2 with all this different rows/columns data.</p>
  
  <p>Below is sample data, I tried using Seq:</p>
  
  <pre><code>var DF1 = Seq(
    ("11111111", "0101","6573","X1234",12763),
    ("44444444", "0148","8382","Y5678",-2883),
    ("55555555", "0154","5240","Z9011", 8003))
  </code></pre>
  
  <p>I want to add 2 dynamic rows below to the above Seq and then use the final Seq to create a Dataframe.</p>
  
  <pre><code>  ("88888888", "1333","7020","DEF34",500)
    ("99999999", "1333","7020","GHI56",500)
  </code></pre>
  
  <p>Final Seq or Dataframe should look like below:</p>
  
  <pre><code>   var DF3 = Seq(
        ("11111111", "0101","6573","X1234",12763),
        ("44444444", "0148","8382","Y5678",-2883),
        ("55555555", "0154","5240","Z9011", 8003),
        ("88888888", "1333","7020","DEF34",500),
        ("99999999", "1333","7020","GHI56",500))
  </code></pre>
  
  <p>Tried below code using Seq, created Case Class, to use it possibly. Problem is the when a new row is added to a Seq, it returns a new Seq with new row added in. How to get an updated Seq with new row added to it ? If not Seq, is ArrayBuffer a good idea to use ?</p>
  
  <pre><code>  case class CreateDFTestCaseClass(ACCOUNT_NO: String, LONG_IND: String, SHORT_IND: String,SECURITY_ID: String, QUANTITY: Integer)
    val sparkSession = SparkSession
      .builder()
      .appName("AllocationOneViewTest")
      .master("local")
      .getOrCreate()
    val sc = sparkSession.sparkContext
    import sparkSession.sqlContext.implicits._
    def main(args: Array[String]): Unit = {
      var acctRulesPosDF = Seq(
        ("11111111", "0101","6573","X1234",12763),
        ("44444444", "0148","8382","Y5678",-2883),
        ("55555555", "0154","5240","Z9011", 8003))
      acctRulesPosDF:+ ("88888888", "1333","7020","DEF34",500)
      acctRulesPosDF:+ ("99999999", "1333","7020","GHI56",500))
      var DF3 = acctRulesPosDF.toDF
      DF3.show()
  </code></pre>