本文整理汇总了Java中org.apache.flink.api.java.DataSet.collect方法的典型用法代码示例。如果您正苦于以下问题:Java DataSet.collect方法的具体用法?Java DataSet.collect怎么用?Java DataSet.collect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.java.DataSet
的用法示例。
在下文中一共展示了DataSet.collect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAllGroupCombineIdentity
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testAllGroupCombineIdentity() throws Exception {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple3<Integer, Long, String>> reduceDs = ds
// combine
.combineGroup(new IdentityFunction())
// fully reduce
.reduceGroup(new IdentityFunction());
List<Tuple3<Integer, Long, String>> result = reduceDs.collect();
compareResultAsTuples(result, identityResult);
}
示例2: testFirstNOnUngroupedDS
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@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);
}
示例3: testIf
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testIf() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSource<Tuple2<Integer, Boolean>> input =
env.fromElements(new Tuple2<>(5, true));
Table table =
tableEnv.fromDataSet(input, "a, b");
Table result = table.select(
"(b && true).?('true', 'false')," +
"false.?('true', 'false')," +
"true.?(true.?(true.?(10, 4), 4), 4)," +
"?((b && true), 'true', 'false')");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String expected = "true,false,10,true";
compareResultAsText(results, expected);
}
示例4: testAllRejectingFilter
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testAllRejectingFilter() throws Exception {
/*
* Test all-rejecting filter.
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple3<Integer, Long, String>> filterDs = ds.
filter(new Filter1());
List<Tuple3<Integer, Long, String>> result = filterDs.collect();
String expected = "\n";
compareResultAsTuples(result, expected);
}
示例5: testAsFromPrivateFieldsPojo
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testAsFromPrivateFieldsPojo() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
List<PrivateSmallPojo> data = new ArrayList<>();
data.add(new PrivateSmallPojo("Peter", 28, 4000.00, "Sales"));
data.add(new PrivateSmallPojo("Anna", 56, 10000.00, "Engineering"));
data.add(new PrivateSmallPojo("Lucy", 42, 6000.00, "HR"));
Table table = tableEnv
.fromDataSet(env.fromCollection(data),
"department AS a, " +
"age AS b, " +
"salary AS c, " +
"name AS d")
.select("a, b, c, d");
DataSet<Row> ds = tableEnv.toDataSet(table, Row.class);
List<Row> results = ds.collect();
String expected =
"Sales,28,4000.0,Peter\n" +
"Engineering,56,10000.0,Anna\n" +
"HR,42,6000.0,Lucy\n";
compareResultAsText(results, expected);
}
示例6: testProgram
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Override
protected void testProgram() throws Exception {
/*
* Test passing a configuration object to an input format
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
Configuration ifConf = new Configuration();
ifConf.setString("prepend", "test");
DataSet<String> ds = env.createInput(new TestInputFormat(new Path(inputPath))).withParameters(ifConf);
List<String> result = ds.collect();
String expectedResult = "ab\n"
+ "cd\n"
+ "ef\n";
compareResultAsText(result, expectedResult);
}
示例7: testAllPassingFilter
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testAllPassingFilter() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.get3TupleDataSet(env);
Table table = tableEnv.fromDataSet(input, "a, b, c");
Table result = table
.filter("true");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String expected = "1,1,Hi\n" + "2,2,Hello\n" + "3,2,Hello world\n" +
"4,3,Hello world, how are you?\n" + "5,3,I am fine.\n" + "6,3,Luke Skywalker\n" +
"7,4,Comment#1\n" + "8,4,Comment#2\n" + "9,4,Comment#3\n" + "10,4,Comment#4\n" +
"11,5,Comment#5\n" + "12,5,Comment#6\n" + "13,5,Comment#7\n" +
"14,5,Comment#8\n" + "15,5,Comment#9\n" + "16,6,Comment#10\n" +
"17,6,Comment#11\n" + "18,6,Comment#12\n" + "19,6,Comment#13\n" +
"20,6,Comment#14\n" + "21,6,Comment#15\n";
compareResultAsText(results, expected);
}
示例8: testCorrectnessOfDistinctOnTuples
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testCorrectnessOfDistinctOnTuples() throws Exception{
/*
* check correctness of distinct on tuples
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple3<Integer, Long, String>> distinctDs = ds.union(ds).distinct();
List<Tuple3<Integer, Long, String>> result = distinctDs.collect();
String expected = "1,1,Hi\n" +
"2,2,Hello\n" +
"3,2,Hello world\n";
compareResultAsTuples(result, expected);
}
示例9: testJoinWithFilter
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testJoinWithFilter() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
Table in1 = tableEnv.fromDataSet(ds1, "a, b, c");
Table in2 = tableEnv.fromDataSet(ds2, "d, e, f, g, h");
Table result = in1.join(in2).where("b === e && b < 2").select("c, g");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String expected = "Hi,Hallo\n";
compareResultAsText(results, expected);
}
示例10: testAsFromTupleToPojo
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Ignore
@Test
public void testAsFromTupleToPojo() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
List<Tuple4<String, Integer, Double, String>> data = new ArrayList<>();
data.add(new Tuple4<>("Rofl", 1, 1.0, "Hi"));
data.add(new Tuple4<>("lol", 2, 1.0, "Hi"));
data.add(new Tuple4<>("Test me", 4, 3.33, "Hello world"));
Table table = tableEnv
.fromDataSet(env.fromCollection(data), "q, w, e, r")
.select("q as a, w as b, e as c, r as d");
DataSet<SmallPojo2> ds = tableEnv.toDataSet(table, SmallPojo2.class);
List<SmallPojo2> results = ds.collect();
String expected = "Rofl,1,1.0,Hi\n" + "lol,2,1.0,Hi\n" + "Test me,4,3.33,Hello world\n";
compareResultAsText(results, expected);
}
示例11: testCorrectnessOfAllGroupReduceForTuples
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testCorrectnessOfAllGroupReduceForTuples() throws Exception {
/*
* check correctness of all-groupreduce for tuples
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple3<Integer, Long, String>> reduceDs = ds.reduceGroup(new AllAddingTuple3GroupReduce());
List<Tuple3<Integer, Long, String>> result = reduceDs.collect();
String expected = "231,91,Hello World\n";
compareResultAsTuples(result, expected);
}
示例12: testNonPojoToVerifyFullTupleKeys
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testNonPojoToVerifyFullTupleKeys() throws Exception {
/*
* Non-POJO test to verify that full-tuple keys are working.
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds1 = CollectionDataSets.getSmallNestedTupleDataSet(env);
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds2 = CollectionDataSets.getSmallNestedTupleDataSet(env);
DataSet<Tuple2<Tuple2<Tuple2<Integer, Integer>, String>, Tuple2<Tuple2<Integer, Integer>, String>>> joinDs =
ds1.fullOuterJoin(ds2)
.where(0)
.equalTo("f0.f0", "f0.f1") // key is now Tuple2<Integer, Integer>
.with(new ProjectBothFunction<Tuple2<Tuple2<Integer, Integer>, String>, Tuple2<Tuple2<Integer, Integer>, String>>());
env.setParallelism(1);
List<Tuple2<Tuple2<Tuple2<Integer, Integer>, String>, Tuple2<Tuple2<Integer, Integer>, String>>> result = joinDs.collect();
String expected = "((1,1),one),((1,1),one)\n" +
"((2,2),two),((2,2),two)\n" +
"((3,3),three),((3,3),three)\n";
compareResultAsTuples(result, expected);
}
示例13: testIntBasedDefinitionOnGroupSortForFullNestedTuple
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testIntBasedDefinitionOnGroupSortForFullNestedTuple() throws Exception {
/*
* Test int-based definition on group sort, for (full) nested Tuple
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds = CollectionDataSets.getGroupSortedNestedTupleDataSet(env);
DataSet<String> reduceDs = ds.groupBy("f1").sortGroup(0, Order.DESCENDING).reduceGroup(new NestedTupleReducer());
List<String> result = reduceDs.collect();
String expected = "a--(2,1)-(1,3)-(1,2)-\n" +
"b--(2,2)-\n"+
"c--(4,9)-(3,6)-(3,3)-\n";
compareResultAsText(result, expected);
}
示例14: testCorrectnessOfGroupReduceIfUDFReturnsInputObjectsMultipleTimesWhileChangingThem
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testCorrectnessOfGroupReduceIfUDFReturnsInputObjectsMultipleTimesWhileChangingThem() throws Exception{
/*
* check correctness of groupReduce if UDF returns input objects multiple times and changes it in between
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple3<Integer, Long, String>> reduceDs = ds.
groupBy(1).reduceGroup(new InputReturningTuple3GroupReduce());
List<Tuple3<Integer, Long, String>> result = reduceDs.collect();
String expected = "11,1,Hi!\n" +
"21,1,Hi again!\n" +
"12,2,Hi!\n" +
"22,2,Hi again!\n" +
"13,2,Hi!\n" +
"23,2,Hi again!\n";
compareResultAsTuples(result, expected);
}
示例15: testTupleContainingPojosAndRegularFields
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testTupleContainingPojosAndRegularFields() throws Exception {
/*
* Test Tuple containing pojos and regular fields
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, CrazyNested, POJO>> ds = CollectionDataSets.getTupleContainingPojos(env);
DataSet<Integer> reduceDs = ds.groupBy("f0", "f1.*") // nested full tuple selection
.reduceGroup(new GroupReducer4());
List<Integer> result = reduceDs.collect();
String expected = "3\n1\n";
compareResultAsText(result, expected);
}