title: while loop on a map spark dataframe
body: <p>i have this problem with a <strong>mapType</strong> in spark using scala API
  for each session we are sending a map in which you can find the categories the user visited associated with the number of events in each  category </p>
  
  <pre><code>[ home &amp; personal items &gt; interior -&gt; 1, vehicles &gt; cars -&gt; 1] 
  </code></pre>
  
  <p>Not all the user visit the same number of categories so the size of the map changes based on the user_id  </p>
  
  <p>i need to calculate the number of session grouped by category 
  in order to that i need to loop over the map and while its not it's not empty 
  things i've tried before </p>
  
  <pre class="lang-scala prettyprint-override"><code>while (size(col("categoriesRaw")) !== 0) {
      df.select(
          explode(col("categoriesRaw"))
      )
      .select(
          col("key").alias("categ"),
          col("value").alias("number_of_events")
      )
  }
  </code></pre>
  
  <p>but i'm facing some errors like :</p>
  
  <pre><code>type mismatch;
   found   : org.apache.spark.sql.Column
   required: Booleansbt
  </code></pre>