title: How to convert struct function to a named_struct expression correctly?
body: <p>env: spark2.4.3</p>
  <h1>example.json</h1>
  <pre><code>{
      &quot;array0&quot;: [
          {
              &quot;a&quot;: &quot;1&quot;,
              &quot;b&quot;: &quot;2&quot;
          },
          {
              &quot;a&quot;: &quot;3&quot;,
              &quot;b&quot;: &quot;4&quot;
          }
      ]
  }
  </code></pre>
  <p>I need to change every field name of struct in <code>array0</code> to such .json with spark-sql API:</p>
  <pre><code>{
          &quot;array0&quot;: [
              {
                  &quot;A&quot;: &quot;1&quot;,
                  &quot;B&quot;: &quot;2&quot;
              },
              {
                  &quot;A&quot;: &quot;3&quot;,
                  &quot;B&quot;: &quot;4&quot;
              }
          ]
      }
  </code></pre>
  <p>load:</p>
  <pre><code>val source = spark.read.format(&quot;json&quot;).option(&quot;multiLine&quot;, &quot;true&quot;).load(&quot;/home/user/Desktop/example.json&quot;)
  </code></pre>
  <p>And I have to generate my structure with an API because of some specs.(I used <code>struct</code> here, and <code>named_struct</code> is not an API so I can't use it)</p>
  <pre><code>val my_struct = struct(col(&quot;x.a&quot;).as(&quot;A&quot;), col(&quot;x.b&quot;).as(&quot;B&quot;))
  </code></pre>
  <p>Cos in spark2.4.3 transform API hasn't been supported yet so I generate it with the <code>expr()</code> function</p>
  <pre><code>val my_transform = expr(&quot;transform(&quot;+&quot;array0,&quot;+&quot;x-&gt;&quot;+my_struct.expr.sql+&quot;)&quot;)
  </code></pre>
  <p>And it throws:</p>
  <pre><code>org.apache.spark.sql.catalyst.parser.ParseException:
  extraneous input 'AS' expecting {')', ','}(line 1, pos 58)
  </code></pre>
  <p>It seems that <code>expr()</code> doesn't support <code>my_struct.expr.sql</code>. I'm confused.</p>
  <p>So how can I give a correct struct sql string to <code>expr()</code>?</p>
  <p>Or some other solutions anyone can give me?</p>
  <p>Thank you.</p>