title: Spark - convert scala to java
body: <p>Using <code>apache-spark</code> to process data.</p>
  
  <p>Given such <code>scala</code> codes:</p>
  
  <pre><code>val rdd1 = sc.cassandraTable("player", "playerinfo").select("key1", "value")
  val rdd2 = rdd1.map(row =&gt; (row.getString("key1"), row.getLong("value")))
  </code></pre>
  
  <p>Basically, it covert a <code>RDD</code> 'rdd1' to another <code>RDD</code> 'rdd2', but it stores 'rdd1' as key-value pair form. </p>
  
  <p>Pay attention that the source data is from <code>cassandra</code> and <code>keys1</code> is a part of composite key and <code>value</code> is the value.</p>
  
  <p>Then how to convert this into <code>Java</code> so that I will have a <code>JavaPairRDD&lt;String,Long&gt;</code> using spark Java API? I already have an <code>cassandraRowsRDD</code> generated successfully from the Java codes below:</p>
  
  <pre><code>  JavaRDD&lt;String&gt; cassandraRowsRDD = javaFunctions(sc).cassandraTable("player", "playerinfo")
              .map(new Function&lt;CassandraRow, String&gt;() {
                  @Override
                  public String call(CassandraRow cassandraRow) throws Exception {
                      return cassandraRow.toString();
                  }
              });
  </code></pre>