title: how to count distinct values in a column after groupby in scala spark using mapGroups
body: <p>i am new to scala spark. i have a textfile data as</p>
  
  <pre><code>001,delhi,india
  002,chennai,india
  003,hyderabad,india
  004,newyork,us
  005,chicago,us
  006,lasvegas,us
  007,seattle,us
  </code></pre>
  
  <p>i want to count number of distinct city in each country so i have applied groupBy and mapGroups. I am not sure how to count values inside mapGroups.Please find my code below</p>
  
  <pre><code>val ds1 = sparkSession.read.textFile("samplefile.txt").map(x =&gt; x.split(","))
    val ds2 = ds1.groupByKey(x =&gt; x(2)).mapGroups{case(k,iter) =&gt; (k,iter.map(x =&gt; x(2)).toArray)}
  </code></pre>
  
  <p>Please help me with the syntax. I know it can be done easily by spark-sql but I want to do it by scala</p>