title: Swap column values in Spark Dataframe where one is string and other is string inside a struct
body: <p>I have data in dataframe as follows</p>
  <pre><code>{&quot;A&quot;, {4,&quot;B&quot;}}
  </code></pre>
  <p>Schema :</p>
  <pre><code>{&quot;type&quot;:&quot;struct&quot;,&quot;fields&quot;:[{&quot;name&quot;:&quot;lastname&quot;,&quot;nullable&quot;:false,&quot;type&quot;:&quot;string&quot;,&quot;metadata&quot;:{}},{&quot;name&quot;:&quot;name&quot;,&quot;type&quot;:{&quot;type&quot;:&quot;struct&quot;,&quot;fields&quot;:[{&quot;name&quot;:&quot;mid&quot;,&quot;type&quot;:&quot;long&quot;,&quot;nullable&quot;:true,&quot;metadata&quot;:{}},{&quot;name&quot;:&quot;firstname&quot;,&quot;type&quot;:&quot;string&quot;,&quot;nullable&quot;:true,&quot;metadata&quot;:{}}]},&quot;nullable&quot;:true,&quot;metadata&quot;:{}}]}
  </code></pre>
  <p>I want to swap values &quot;A&quot; and &quot;B&quot; so that the output looks like below</p>
  <pre><code>{&quot;B&quot;, {4,&quot;A&quot;}}
  </code></pre>
  <p>Can we achieve this without using functions like map? Can withColumn, select be used to achieve this in Java? I want to avoid using any row level action like map because we need to pass Encoders to those functions and due to some limitation I cannot pass encoder.</p>
  <p>df.show()</p>
  <pre><code>+--------+------+
  |lastname|  name|
  +--------+------+
  |       A|[4, B]|
  |       C|[5, D]|
  +--------+------+
  </code></pre>
  <p>df.printSchema()</p>
  <pre><code>root
   |-- lastname: string (nullable = false)
   |-- name: struct (nullable = true)
   |    |-- mid: long (nullable = true)
   |    |-- firstname: string (nullable = true)
  </code></pre>