use of org.apache.flink.batch.connectors.cassandra.CassandraPojoOutputFormat in project flink by apache.
the class BatchPojoExample method main.
public static void main(String[] args) throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
List<Pojo> customCassandraAnnotatedPojos = IntStream.range(0, 20).mapToObj(x -> new Pojo(UUID.randomUUID().toString(), x, 0)).collect(Collectors.toList());
DataSet<Pojo> dataSet = env.fromCollection(customCassandraAnnotatedPojos);
ClusterBuilder clusterBuilder = new ClusterBuilder() {
private static final long serialVersionUID = -1754532803757154795L;
@Override
protected Cluster buildCluster(Cluster.Builder builder) {
return builder.addContactPoints("127.0.0.1").build();
}
};
dataSet.output(new CassandraPojoOutputFormat<>(clusterBuilder, Pojo.class, () -> new Mapper.Option[] { Mapper.Option.saveNullFields(true) }));
env.execute("Write");
/*
* This is for the purpose of showing an example of creating a DataSet using CassandraPojoInputFormat.
*/
DataSet<Pojo> inputDS = env.createInput(new CassandraPojoInputFormat<>(SELECT_QUERY, clusterBuilder, Pojo.class, () -> new Mapper.Option[] { Mapper.Option.consistencyLevel(ConsistencyLevel.ANY) }));
inputDS.print();
}
use of org.apache.flink.batch.connectors.cassandra.CassandraPojoOutputFormat in project flink by apache.
the class CassandraConnectorITCase method writePojosWithOutputFormat.
private <T> List<T> writePojosWithOutputFormat(Class<T> annotatedPojoClass) throws Exception {
final CassandraPojoOutputFormat<T> sink = new CassandraPojoOutputFormat<>(builderForWriting, annotatedPojoClass, () -> new Mapper.Option[] { Mapper.Option.saveNullFields(true) });
final Constructor<T> pojoConstructor = getPojoConstructor(annotatedPojoClass);
List<T> pojos = new ArrayList<>();
for (int i = 0; i < 20; i++) {
pojos.add(pojoConstructor.newInstance(UUID.randomUUID().toString(), i, 0));
}
try {
sink.configure(new Configuration());
sink.open(0, 1);
for (T pojo : pojos) {
sink.writeRecord(pojo);
}
} finally {
sink.close();
}
return pojos;
}
Aggregations