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);
}
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);
}
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);
}
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);
}
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");
}
Aggregations