title: Applying a structure-preserving UDF to a column of structs in a dataframe
body: <p>I have the schema </p>
  
  <pre class="lang-none prettyprint-override"><code> |-- count: struct (nullable = true)
   |    |-- day1: long (nullable = true)
   |    |-- day2: long (nullable = true)
   |    |-- day3: long (nullable = true)
   |    |-- day4: long (nullable = true)
   |-- key: string (nullable = true)
  </code></pre>
  
  <p>and I would like to do a transformation on the data such that the structure of <code>count</code> is preserved, i.e., it still has four fields (day1, day2,...) of type <code>long</code>. The transformation I'd like to do is add the value of the <code>day1</code> field to the other fields. My idea was to use a UDF but I'm not sure how 1) to have the UDF return a struct with the same structure and 2) how, within the UDF, to access the fields of the struct that it's transforming (in order to get the value of the <code>day1</code> field). The logic for the UDF should be simple, something like </p>
  
  <pre><code>s : StructType =&gt; StructType(s.day1, s.day1+s.day2, s.day1+s.day3,s.day1+s.day4)
  </code></pre>
  
  <p>but I don't know how to get the correct types/preserve the field names of the original structure. I'm very new to Spark so any guidance is much appreciated. </p>
  
  <p>Also, I would greatly appreciate it if anyone could point me to the right documentation for this type of thing. I feel that this type of simple transformation should be very simple but I was reading the Spark docs and it wasn't clear to me how this is done.</p>