title: Spark combineByKey over reduceBykey using Java
body: <p>I have the below dataset:</p>
  
  <pre><code>    key   value
  ---------------------------
      key1,CLASS-A,YES,1
      key2,CLASS-B,YES,2
      key2,CLASS-B,YES,1
      key1,CLASS-A,YES,4
      key3,CLASS-C,DEFAULT,1
  </code></pre>
  
  <p>OUTPUT should look like:</p>
  
  <pre><code>    key   value
  ---------------------------
  key1,    CLASS-A,YES,5
  key2,    CLASS-B,YES,3
  key3,    CLASS-C,NO,1
  </code></pre>
  
  <p>While using reduceByKey to obtain the result , i found that whenever there is a key with only one value , in this case key3, the reduceByKey is not called as there is nothing to reduce against.And I get :</p>
  
  <pre><code>   key   value
  ---------------------------
  key1,    CLASS-A,YES,5
  key2,    CLASS-B,YES,3
  key3,    CLASS-C,DEAFULT,1
  </code></pre>
  
  <p>Can  I achieve this using combineByKey in Spark (Java) . </p>
  
  <p>What I tried so far :</p>
  
  <pre><code>reduceByKey(
                      new Function2&lt;String, String, String&gt;() {
  
                          @Override
                          public String call(String s1, String s2) throws Exception {
                              String[] vals1 = StringUtils.split(s1, ",");
                              String[] vals2 = StringUtils.split(s2, ",");
  
                              String jobStat1 = vals1[0];
                              String jobStat2 = vals2[0];
  
                              String reducedJobStat;
  
  
                              boolean s1 = jobStat1.equals("YES")
  
                              boolean s2 = jobStat2.equals("YES");
  
                              if (s1 || s2) {
  
                                  reducedJobStat = "YES";
                              } else {
  
                                  reducedJobStat = "NO";
                              }
  
  
                              return reducedJobStat;
                          }
                      }
              )
  </code></pre>