title: Using a case class to rename split columns with Spark Dataframe
body: <p>I am splitting 'split_column' to another five columns as per the following code. However I wanted to have this new columns to be renamed so that they would have some meaningful names(let's say new_renamed1", "new_renamed2", "new_renamed3", "new_renamed4", "new_renamed5" in this example) </p>
  
  <pre><code>val df1 = df.withColumn("new_column", split(col("split_column"), "\\|")).select(col("*") +: (0 until 5).map(i =&gt; col("new_column").getItem(i).as(s"newcol$i")): _*).drop("split_column","new_column")
  
  val new_columns_renamed = Seq("....., "new_renamed1", "new_renamed2", "new_renamed3", "new_renamed4", "new_renamed5") 
  
  val df2 = df1.toDF(new_columns_renamed: _*)
  </code></pre>
  
  <p>However issue with this approach is some of my splits might have more than fifty new rows. In thi renaming  approach, a little typo (like extra comma, missing double quotes) would be painful to detect.</p>
  
  <p>Is there a way to rename columns with  case class like below ?</p>
  
  <pre><code>case class SplittedRecord (new_renamed1: String, new_renamed2: String, new_renamed3: String, new_renamed4: String, new_renamed5: String)
  </code></pre>
  
  <p>Please note that in the actual scenario names would not look like new_renamed1, new_renamed2, ......, new_renamed5 , they would be totally different.</p>