title: How to count occurrences of a word inside a Array in scala when using spark?
body: <p>In spark, I have a RDD which is :</p>
  
  <pre><code>textRDD[Text]
  </code></pre>
  
  <p>Here "Text" is a class with:</p>
  
  <pre><code>(String, Array[String])
  </code></pre>
  
  <p>I wish to know in this RDD how many strings in the array are the same as my target string, so is there any way to count the number of that?</p>
  
  <p>The first thing I have is something like:</p>
  
  <pre><code>val count = textRDD.aggregate(0)(seqOp, (acc1, acc2) =&gt; acc1 + acc2))
  </code></pre>
  
  <p>But I have no idea about how to design seqOp in this case. </p>
  
  <p>For example:</p>
  
  <pre><code>textRDD = sc.parallelize(
       List(
           ("s1", Array("this", "is", "a", "sentence", "about", math)),
           ("s2", Array("math", "is", "an", "english", "word", "in" "english")),
           ("s3", Array("computer", "science", "is", "a", "science", "with", "math"))
           )
  </code></pre>
  
  <p>How can I count the num of "math"?</p>