Search in sources :

Example 56 with DataSet

use of org.apache.flink.api.java.DataSet 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();
}
Also used : ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) IntStream(java.util.stream.IntStream) DataSet(org.apache.flink.api.java.DataSet) List(java.util.List) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) CassandraPojoOutputFormat(org.apache.flink.batch.connectors.cassandra.CassandraPojoOutputFormat) Cluster(com.datastax.driver.core.Cluster) Mapper(com.datastax.driver.mapping.Mapper) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CassandraPojoInputFormat(org.apache.flink.batch.connectors.cassandra.CassandraPojoInputFormat) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder)

Aggregations

DataSet (org.apache.flink.api.java.DataSet)56 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)31 Test (org.junit.Test)24 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)17 DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)11 Plan (org.apache.flink.api.common.Plan)10 Types (org.apache.flink.api.common.typeinfo.Types)10 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)10 Assert (org.junit.Assert)10 Arrays (java.util.Arrays)9 Rule (org.junit.Rule)9 List (java.util.List)8 MapFunction (org.apache.flink.api.common.functions.MapFunction)8 Configuration (org.apache.flink.configuration.Configuration)7 Graph (org.apache.flink.graph.Graph)7 NullValue (org.apache.flink.types.NullValue)7 ArrayList (java.util.ArrayList)6 GroupReduceFunction (org.apache.flink.api.common.functions.GroupReduceFunction)6 KeySelector (org.apache.flink.api.java.functions.KeySelector)6 PythonMapPartition (org.apache.flink.python.api.functions.PythonMapPartition)6