title: Spark scala:-Getting error the way i am trying to use if statement within reduceByKey
body: <p>In bellow program i am trying to use if statement within <code>reduceByKey</code> but getting error.</p>
  
  <p>Bellow is my data which contains userid , shopname and rating:-</p>
  
  <pre><code>UserId ShopName  Rating
  192     FBB        3.5
  192     Reliance   4.9
  192     Soch       2.0
  20      Reliance   5.0
  20      FBB        4.0
  301     Soch       2.6
  301     W Printed  3.9
  </code></pre>
  
  <p>Question:</p>
  
  <p><strong>Find those shopnames which have not got ratings below 4 by any user. Answer should be shop Reliance as it has not got rating bellow 4 by any user.</strong></p>
  
  <p>Bellow is my code:</p>
  
  <pre><code>val rdd=sc.textFile("Filepath\shoprating.dat")
  val shop_rating=rdd.map(i=&gt;i.split(" ")).map(i =&gt; (i(1),i(2).toDouble))
  
  val GB_shop=shop_rating.groupByKey()
  
  val Shopnames = GB_shop.reduceByKey((x, y) =&gt; if(x._2&gt;=4 &amp;&amp; y._2&gt;=4)x )
  
  Shopnames.collect
  </code></pre>
  
  <p>But the way i am using if statement inside <code>reduceByKey</code> is not working. So pls help me with the code.what exactly i need to do to get correct output.</p>