title: Fixed length parsing in spark scala
body: <p>I have created the dataframe and the input is like this: </p>
  
  <pre><code>   +-----------------------------------+
     |value                              |
     +-----------------------------------+
     |1   PRE123                    21   |
     |2   TEST                      32   |
     |7   XYZ                       .7   |
     +-----------------------------------+
  </code></pre>
  
  <p>and on the basis on the below metadata information we need to split the above data frame and create a new dataframe, having columns name id,name and class and it start and index loction is given in this json meta data.</p>
  
  <pre><code>   {
      "columnName": "id",
      "start": 1,
      "end": 2
    },
    {
      "columnName": "name",
      "start": 5,
      "end": 10
    },
    {
      "columnName": "class",
      "start": 20,
      "end": 22
    }
  </code></pre>
  
  <p>OUTPUT : </p>
  
  <pre><code>  +---+------+-----+
    | id|  name|class|
    +---+------+-----+
    |  1|PRE123|   21|
    |  2|  TEST|   32|
    |  7|   XYZ|   .7|
    +---+------+-----+
  </code></pre>
  
  <p>For loading the df, I have created the list:  </p>
  
  <pre><code>   list.+=(loadedDF.col("value").substr(fixedLength.getStart, (fixedLength.getEnd - fixedLength.getStart)).alias(fixedLength.getColumnName))
  </code></pre>
  
  <p>and from this list, I have created the dataframe </p>
  
  <pre><code>var df: DataFrame = loadedDF.select(list: _*)
  </code></pre>
  
  <p>Need to know the order better approach for creating the dataframe from the metadata. 
  As the list created will bring all the data to the driver node.</p>