Class CassandraIO
Reading from Apache Cassandra
CassandraIO
provides a source to read and returns a bounded collection of entities as
PCollection<Entity>
. An entity is built by Cassandra mapper (
com.datastax.driver.mapping.EntityMapper
) based on a POJO containing annotations (as described
http://docs.datastax .com/en/developer/java-driver/2.1/manual/object_mapper/creating/").
The following example illustrates various options for configuring the IO:
pipeline.apply(CassandraIO.<Person>read()
.withHosts(Arrays.asList("host1", "host2"))
.withPort(9042)
.withKeyspace("beam")
.withTable("Person")
.withEntity(Person.class)
.withCoder(SerializableCoder.of(Person.class))
// above options are the minimum set, returns PCollection<Person>
Alternatively, one may use CassandraIO.<Person>readAll()
.withCoder(SerializableCoder.of(Person.class))
to query a subset of the Cassandra database by
creating a PCollection of CassandraIO.Read<Person>
each with their own query or
RingRange.
Writing to Apache Cassandra
CassandraIO
provides a sink to write a collection of entities to Apache Cassandra.
The following example illustrates various options for configuring the IO write:
pipeline
.apply(...) // provides a PCollection<Person> where Person is an entity
.apply(CassandraIO.<Person>write()
.withHosts(Arrays.asList("host1", "host2"))
.withPort(9042)
.withKeyspace("beam")
.withEntity(Person.class));
Cassandra Socket Options
The following example illustrates setting timeouts for the Cassandra client:
pipeline.apply(CassandraIO.<Person>read()
.withHosts(Arrays.asList("host1", "host2"))
.withPort(9042)
.withConnectTimeout(1000)
.withReadTimeout(5000)
.withKeyspace("beam")
.withTable("Person")
.withEntity(Person.class)
.withCoder(SerializableCoder.of(Person.class))
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Specify the mutation type: either write or delete.static class
APTransform
to read data from Apache Cassandra.static class
APTransform
to read data from Apache Cassandra.static class
APTransform
to mutate into Apache Cassandra. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CassandraIO.Write
<T> delete()
Provide aCassandraIO.Write
PTransform
to delete data to a Cassandra database.static <T> CassandraIO.Read
<T> read()
Provide aCassandraIO.Read
PTransform
to read data from a Cassandra database.static <T> CassandraIO.ReadAll
<T> readAll()
Provide aCassandraIO.ReadAll
PTransform
to read data from a Cassandra database.static <T> CassandraIO.Write
<T> write()
Provide aCassandraIO.Write
PTransform
to write data to a Cassandra database.
-
Method Details
-
read
Provide aCassandraIO.Read
PTransform
to read data from a Cassandra database. -
readAll
Provide aCassandraIO.ReadAll
PTransform
to read data from a Cassandra database. -
write
Provide aCassandraIO.Write
PTransform
to write data to a Cassandra database. -
delete
Provide aCassandraIO.Write
PTransform
to delete data to a Cassandra database.
-