Search in sources :

Example 1 with Tuple1

use of org.apache.flink.api.java.tuple.Tuple1 in project flink by apache.

the class DistinctITCase method testCorrectnessOfDistinctOnCustomTypeWithTypeExtractor.

@Test
public void testCorrectnessOfDistinctOnCustomTypeWithTypeExtractor() throws Exception {
    /*
		 * check correctness of distinct on custom type with type extractor
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<Tuple1<Integer>> reduceDs = ds.distinct(new KeySelector3()).map(new Mapper3());
    List<Tuple1<Integer>> result = reduceDs.collect();
    String expected = "1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "6\n";
    compareResultAsTuples(result, expected);
}
Also used : CustomType(org.apache.flink.test.javaApiOperators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Test(org.junit.Test)

Example 2 with Tuple1

use of org.apache.flink.api.java.tuple.Tuple1 in project flink by apache.

the class FirstNITCase method testFirstNOnUngroupedDS.

@Test
public void testFirstNOnUngroupedDS() throws Exception {
    /*
		 * First-n on ungrouped data set
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
    DataSet<Tuple1<Integer>> seven = ds.first(7).map(new OneMapper()).sum(0);
    List<Tuple1<Integer>> result = seven.collect();
    String expected = "(7)\n";
    compareResultAsText(result, expected);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Test(org.junit.Test)

Example 3 with Tuple1

use of org.apache.flink.api.java.tuple.Tuple1 in project flink by apache.

the class DistinctITCase method testCorrectnessOfDistinctOnTuplesWithKeyFieldSelectorWithNotAllFieldsSelected.

@Test
public void testCorrectnessOfDistinctOnTuplesWithKeyFieldSelectorWithNotAllFieldsSelected() throws Exception {
    /*
		 * check correctness of distinct on tuples with key field selector with not all fields selected
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds = CollectionDataSets.getSmall5TupleDataSet(env);
    DataSet<Tuple1<Integer>> distinctDs = ds.union(ds).distinct(0).project(0);
    List<Tuple1<Integer>> result = distinctDs.collect();
    String expected = "1\n" + "2\n";
    compareResultAsTuples(result, expected);
}
Also used : Tuple5(org.apache.flink.api.java.tuple.Tuple5) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Test(org.junit.Test)

Example 4 with Tuple1

use of org.apache.flink.api.java.tuple.Tuple1 in project flink by apache.

the class HBaseConnectorITCase method testTableInputFormat.

@Test
public void testTableInputFormat() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(4);
    DataSet<Tuple1<Integer>> result = env.createInput(new InputFormatForTestTable()).reduce(new ReduceFunction<Tuple1<Integer>>() {

        @Override
        public Tuple1<Integer> reduce(Tuple1<Integer> v1, Tuple1<Integer> v2) throws Exception {
            return Tuple1.of(v1.f0 + v2.f0);
        }
    });
    List<Tuple1<Integer>> resultSet = result.collect();
    assertEquals(1, resultSet.size());
    assertEquals(360, (int) resultSet.get(0).f0);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple1(org.apache.flink.api.java.tuple.Tuple1) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with Tuple1

use of org.apache.flink.api.java.tuple.Tuple1 in project flink by apache.

the class BoltTokenizerWordCountWithNames method main.

// *************************************************************************
// PROGRAM
// *************************************************************************
public static void main(final String[] args) throws Exception {
    if (!parseParameters(args)) {
        return;
    }
    // set up the execution environment
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    // get input data
    final DataStream<Tuple1<String>> text = getTextDataStream(env);
    final DataStream<Tuple2<String, Integer>> counts = text.transform("BoltTokenizerWithNames", TypeExtractor.getForObject(new Tuple2<String, Integer>("", 0)), new BoltWrapper<Tuple1<String>, Tuple2<String, Integer>>(new BoltTokenizerByName(), new Fields("sentence"))).keyBy(0).sum(1);
    // emit result
    if (fileOutput) {
        counts.writeAsText(outputPath);
    } else {
        counts.print();
    }
    // execute program
    env.execute("Streaming WordCount with schema bolt tokenizer");
}
Also used : Fields(org.apache.storm.tuple.Fields) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) BoltTokenizerByName(org.apache.flink.storm.wordcount.operators.BoltTokenizerByName)

Aggregations

Tuple1 (org.apache.flink.api.java.tuple.Tuple1)84 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)70 Test (org.junit.Test)67 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)34 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)21 ReplicatingInputFormat (org.apache.flink.api.common.io.ReplicatingInputFormat)16 Plan (org.apache.flink.api.common.Plan)15 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)15 FileInputSplit (org.apache.flink.core.fs.FileInputSplit)13 Path (org.apache.flink.core.fs.Path)13 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)10 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)10 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)9 ShipStrategyType (org.apache.flink.runtime.operators.shipping.ShipStrategyType)8 MapFunction (org.apache.flink.api.common.functions.MapFunction)7 ArrayList (java.util.ArrayList)4 KeySelector (org.apache.flink.api.java.functions.KeySelector)4 IOException (java.io.IOException)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 ConnectedComponents (org.apache.flink.examples.java.graph.ConnectedComponents)3