org.apache.flink.batch.connectors.cassandra.CustomCassandraAnnotatedPojo Java Examples
The following examples show how to use
org.apache.flink.batch.connectors.cassandra.CustomCassandraAnnotatedPojo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BatchPojoExample.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20) .mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0)) .collect(Collectors.toList()); DataSet<CustomCassandraAnnotatedPojo> 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, CustomCassandraAnnotatedPojo.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<CustomCassandraAnnotatedPojo> inputDS = env .createInput(new CassandraPojoInputFormat<>( SELECT_QUERY, clusterBuilder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.consistencyLevel(ConsistencyLevel.ANY)} )); inputDS.print(); }
Example #2
Source File: BatchPojoExample.java From flink with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20) .mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0)) .collect(Collectors.toList()); DataSet<CustomCassandraAnnotatedPojo> 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, CustomCassandraAnnotatedPojo.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<CustomCassandraAnnotatedPojo> inputDS = env .createInput(new CassandraPojoInputFormat<>( SELECT_QUERY, clusterBuilder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.consistencyLevel(ConsistencyLevel.ANY)} )); inputDS.print(); }
Example #3
Source File: BatchPojoExample.java From flink with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20) .mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0)) .collect(Collectors.toList()); DataSet<CustomCassandraAnnotatedPojo> 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, CustomCassandraAnnotatedPojo.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<CustomCassandraAnnotatedPojo> inputDS = env .createInput(new CassandraPojoInputFormat<>( SELECT_QUERY, clusterBuilder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.consistencyLevel(ConsistencyLevel.ANY)} )); inputDS.print(); }
Example #4
Source File: CassandraConnectorITCase.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testCassandraBatchPojoFormat() throws Exception { session.execute(CREATE_TABLE_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME)); OutputFormat<CustomCassandraAnnotatedPojo> sink = new CassandraPojoOutputFormat<>(builder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.saveNullFields(true)}); List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20) .mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0)) .collect(Collectors.toList()); try { sink.configure(new Configuration()); sink.open(0, 1); for (CustomCassandraAnnotatedPojo customCassandraAnnotatedPojo : customCassandraAnnotatedPojos) { sink.writeRecord(customCassandraAnnotatedPojo); } } finally { sink.close(); } ResultSet rs = session.execute(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME)); Assert.assertEquals(20, rs.all().size()); InputFormat<CustomCassandraAnnotatedPojo, InputSplit> source = new CassandraPojoInputFormat<>(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, "batches"), builder, CustomCassandraAnnotatedPojo.class); List<CustomCassandraAnnotatedPojo> result = new ArrayList<>(); try { source.configure(new Configuration()); source.open(null); while (!source.reachedEnd()) { CustomCassandraAnnotatedPojo temp = source.nextRecord(null); result.add(temp); } } finally { source.close(); } Assert.assertEquals(20, result.size()); result.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter)); customCassandraAnnotatedPojos.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter)); assertThat(result, samePropertyValuesAs(customCassandraAnnotatedPojos)); }
Example #5
Source File: CassandraConnectorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCassandraBatchPojoFormat() throws Exception { session.execute(CREATE_TABLE_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME)); OutputFormat<CustomCassandraAnnotatedPojo> sink = new CassandraPojoOutputFormat<>(builder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.saveNullFields(true)}); List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20) .mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0)) .collect(Collectors.toList()); try { sink.configure(new Configuration()); sink.open(0, 1); for (CustomCassandraAnnotatedPojo customCassandraAnnotatedPojo : customCassandraAnnotatedPojos) { sink.writeRecord(customCassandraAnnotatedPojo); } } finally { sink.close(); } ResultSet rs = session.execute(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME)); Assert.assertEquals(20, rs.all().size()); InputFormat<CustomCassandraAnnotatedPojo, InputSplit> source = new CassandraPojoInputFormat<>(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, "batches"), builder, CustomCassandraAnnotatedPojo.class); List<CustomCassandraAnnotatedPojo> result = new ArrayList<>(); try { source.configure(new Configuration()); source.open(null); while (!source.reachedEnd()) { CustomCassandraAnnotatedPojo temp = source.nextRecord(null); result.add(temp); } } finally { source.close(); } Assert.assertEquals(20, result.size()); result.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter)); customCassandraAnnotatedPojos.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter)); assertThat(result, samePropertyValuesAs(customCassandraAnnotatedPojos)); }
Example #6
Source File: CassandraConnectorITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCassandraBatchPojoFormat() throws Exception { session.execute(CREATE_TABLE_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME)); OutputFormat<CustomCassandraAnnotatedPojo> sink = new CassandraPojoOutputFormat<>(builder, CustomCassandraAnnotatedPojo.class, () -> new Mapper.Option[]{Mapper.Option.saveNullFields(true)}); List<CustomCassandraAnnotatedPojo> customCassandraAnnotatedPojos = IntStream.range(0, 20) .mapToObj(x -> new CustomCassandraAnnotatedPojo(UUID.randomUUID().toString(), x, 0)) .collect(Collectors.toList()); try { sink.configure(new Configuration()); sink.open(0, 1); for (CustomCassandraAnnotatedPojo customCassandraAnnotatedPojo : customCassandraAnnotatedPojos) { sink.writeRecord(customCassandraAnnotatedPojo); } } finally { sink.close(); } ResultSet rs = session.execute(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, CustomCassandraAnnotatedPojo.TABLE_NAME)); Assert.assertEquals(20, rs.all().size()); InputFormat<CustomCassandraAnnotatedPojo, InputSplit> source = new CassandraPojoInputFormat<>(SELECT_DATA_QUERY.replace(TABLE_NAME_VARIABLE, "batches"), builder, CustomCassandraAnnotatedPojo.class); List<CustomCassandraAnnotatedPojo> result = new ArrayList<>(); try { source.configure(new Configuration()); source.open(null); while (!source.reachedEnd()) { CustomCassandraAnnotatedPojo temp = source.nextRecord(null); result.add(temp); } } finally { source.close(); } Assert.assertEquals(20, result.size()); result.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter)); customCassandraAnnotatedPojos.sort(Comparator.comparingInt(CustomCassandraAnnotatedPojo::getCounter)); assertThat(result, samePropertyValuesAs(customCassandraAnnotatedPojos)); }