Skip to content

Instantly share code, notes, and snippets.

@RussellSpitzer
Created August 23, 2015 05:33
Show Gist options
  • Save RussellSpitzer/437f57dae4fd4bc4f32d to your computer and use it in GitHub Desktop.
Save RussellSpitzer/437f57dae4fd4bc4f32d to your computer and use it in GitHub Desktop.
import com.datastax.spark.connector._
import com.datastax.spark.connector.cql._
import org.apache.spark.SparkContext
def twoClusterExample ( sc: SparkContext) = {
val connectorToClusterOne = CassandraConnector(sc.getConf.set("spark.cassandra.connection.host", "127.0.0.1"))
val connectorToClusterTwo = CassandraConnector(sc.getConf.set("spark.cassandra.connection.host", "127.0.0.2"))
val rddFromClusterOne = {
// Sets connectorToClusterOne as default connection for everything in this code block
implicit val c = connectorToClusterOne
sc.cassandraTable("ks","tab")
}
{
//Sets connectorToClusterTwo as the default connection for everything in this code block
implicit val c = connectorToClusterTwo
rddFromClusterOne.saveToCassandra("ks","tab")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment