Kotlin wrapper for Java Spark-Cassandra API. Extends JavaSparkContext
and JavaRDD
functionality. Simplifies working with Cassandra data using Apache Spark with Java API.
repositories {
...
maven { url "https://jitpack.io" }
}
compile 'com.github.cortwave:spark-kassandra-extensions:0.2.1'
Briefing
Table with name users exists in test keyspace. Table has next structure:
Column name | Type |
---|---|
text PK | |
age | int |
name | text |
city | text |
User
Java POJO:
public class User {
private String email;
private String name;
private Integer age;
private String city;
... //getters and setters
}
or User
Kotlin data class:
data class Users(val email: String, val age: Int, val city: String, val name: String)
- Java example
CassandraTableScanJavaRDD<CassandraRow> usersUntypedTable = CassandraJavaUtil.javaFunctions(sparkContext)
.cassandraTable("test", "users");
- Kotlin example
val usersUntypedTable = sparkContext.cassandraTableRows("test", "users")
- Java example
CassandraTableScanJavaRDD<User> usersTable = CassandraJavaUtil.javaFunctions(sparkContext)
.cassandraTable("test", "users", CassandraJavaUtil.mapRowTo(User.class));
- Kotlin example
val usersTable = sparkContext.cassandraTable<User>("test", "users")
users type - JavaRDD<User>
- Java example
CassandraJavaUtil.javaFunctions(users)
.writerBuilder("test", "users", CassandraJavaUtil.mapToRow(User.class)).saveToCassandra();
- Kotlin example
users.saveToCassandra("test", "users")