title: How to null a struct in Scala spark when all values in the struct are null?
body: <p>I have a spark scala data frame with a column that is a struct and I want null instead of objects when all values in struct are null.</p>
  <pre><code>val someDF = Seq(
    (8, null,null),
    (64, &quot;mouse&quot;, &quot;s&quot;),
    (-27, &quot;horse&quot;, &quot;e&quot;)
  ).toDF(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;)
  
  def make_week_struct (week:String) : Column = {
    
     val summary = struct($&quot;b&quot;, $&quot;c&quot;).alias(s&quot;wks_${week}_jrny&quot;)
    
     return summary
  }
  
  val week1_summary = make_week_struct(&quot;1&quot;)
  
  var dd = someDF.select($&quot;a&quot;,week1_summary)
  
  display(dd)
  </code></pre>
  <p>Sample Data</p>
  <pre><code>a       b        c       
  8       null     null
  64      mouse    s    
  -27     horse    e   
  </code></pre>
  <p>Current Output</p>
  <pre><code>a   wks_1_jrny
  8   object:{a:null, b:null}
  64  object:{a:&quot;mouse&quot;, b:&quot;s&quot;}
  -27 object:{a:&quot;horse&quot;, b:&quot;e&quot;}
  </code></pre>
  <p>Expected Output</p>
  <pre><code>a   wks_1_jrny
  8   null
  64  object:{a:&quot;mouse&quot;, b:&quot;s&quot;}
  -27 object:{a:&quot;horse&quot;, b:&quot;e&quot;}
  </code></pre>