title: Apache Spark - How to count similar key/value pair in Paired RDD
body: <p>I have <code>rdd</code> of type <code>RDD[(String, String)]</code>:</p>
  
  <p><strong>Input RDD:</strong></p>
  
  <pre><code>val rdd = sc.parallelize(Seq(("java", "perl"),(".Net", "php"),("java","perl")))
  
  (java, perl)
  (.Net, php)
  (java, perl)
  </code></pre>
  
  <p>I want output <code>RDD[(String, String, Int)]</code> where the third item in the tuple will be the count of similar sets. e.g:</p>
  
  <p><strong>Output RDD:</strong></p>
  
  <pre><code>(java, perl, 2)
  (.Net, php, 1)
  </code></pre>
  
  <p>I tried adding one to each record in the input RDD, then reducing by key to get the count:</p>
  
  <pre><code>val t = rdd.map { case (a,b) =&gt; (a,b,1) }
  (java, perl, 1)
  (.Net, php, 1)
  (java, perl, 1)
  </code></pre>
  
  <p>But <code>t.reduceByKey((a,b,c) =&gt; (a,b,c))</code> is giving an error: </p>
  
  <pre><code>value reduceByKey is not a member of org.apache.spark.rdd.RDD[(String, String, Int)]
  t.reduceByKey((a,b,c) =&gt; (a,b,c))
  </code></pre>
  
  <p>I will also be converting the output RDD to a DataFrame.</p>