title: Rename nested field in spark dataframe
body: <p>Having a dataframe <code>df</code> in Spark:</p>
  
  <pre><code> |-- array_field: array (nullable = true)
   |    |-- element: struct (containsNull = true)
   |    |    |-- a: string (nullable = true)
   |    |    |-- b: long (nullable = true)
   |    |    |-- c: long (nullable = true)
  </code></pre>
  
  <p>How to rename field <code>array_field.a</code> to <code>array_field.a_renamed</code>?</p>
  
  <p>[Update]:</p>
  
  <p><code>.withColumnRenamed()</code> does not work with nested fields so I tried this hacky and unsafe method:</p>
  
  <pre><code># First alter the schema:
  schema = df.schema
  schema['array_field'].dataType.elementType['a'].name = 'a_renamed'
  
  ind = schema['array_field'].dataType.elementType.names.index('a')
  schema['array_field'].dataType.elementType.names[ind] = 'a_renamed'
  
  # Then set dataframe's schema with altered schema
  df._schema = schema
  </code></pre>
  
  <p>I know that setting a private attribute is not a good practice but I don't know other way to set the schema for df</p>
  
  <p>I think I am on a right track but <code>df.printSchema()</code> still shows the old name for <code>array_field.a</code>, though <code>df.schema == schema</code> is <code>True</code></p>