Created
July 20, 2018 10:14
-
-
Save samuelorji/3ebd895935a9a221a482b5e666b6eeb4 to your computer and use it in GitHub Desktop.
A simple script that connects to a cassandra cluster and fetches data from it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cassandra | |
import com.datastax.spark.connector.rdd.CassandraTableScanRDD | |
import org.apache.spark.{SparkConf, SparkContext} | |
object battles { | |
case class Battle( | |
battle_number: Option[Integer], | |
year: Option[Integer], | |
attacker_king: Option[String], | |
defender_king: Option[String] | |
) | |
def main(args : Array[String]) : Unit = { | |
// val sc = new SparkContext("local[*]","got-battles",) | |
val conf = new SparkConf().setAppName("got-battles").setMaster("local[*]") | |
.set("spark.cassandra.connection.host", "127.0.0.1") | |
val sc = new SparkContext(conf) | |
val battles :Array[Battle]= CassandraTableScanRDD[Battle](sc, "dev", "battles") | |
.select("battle_number", "year", "attacker_king", "defender_king").collect() | |
battles.foreach { | |
b: Battle => | |
println("Battle Number %s was defended by %s.".format(b.battle_number.getOrElse("unknown"), b.defender_king.getOrElse("No One"))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment