本文整理汇总了Java中org.apache.flink.api.java.tuple.Tuple1类的典型用法代码示例。如果您正苦于以下问题:Java Tuple1类的具体用法?Java Tuple1怎么用?Java Tuple1使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tuple1类属于org.apache.flink.api.java.tuple包,在下文中一共展示了Tuple1类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTableInputFormat
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@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);
}
示例2: checkJoinWithReplicatedSourceInputBehindMapChangingparallelism
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
/**
* Tests compiler fail for join program with replicated data source behind map and changing parallelism.
*/
@Test(expected = CompilerException.class)
public void checkJoinWithReplicatedSourceInputBehindMapChangingparallelism() {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
env.setParallelism(DEFAULT_PARALLELISM);
TupleTypeInfo<Tuple1<String>> typeInfo = TupleTypeInfo.getBasicTupleTypeInfo(String.class);
ReplicatingInputFormat<Tuple1<String>, FileInputSplit> rif =
new ReplicatingInputFormat<Tuple1<String>, FileInputSplit>(new TupleCsvInputFormat<Tuple1<String>>(new Path("/some/path"), typeInfo));
DataSet<Tuple1<String>> source1 = env.createInput(rif, new TupleTypeInfo<Tuple1<String>>(BasicTypeInfo.STRING_TYPE_INFO));
DataSet<Tuple1<String>> source2 = env.readCsvFile("/some/otherpath").types(String.class);
DataSink<Tuple2<Tuple1<String>, Tuple1<String>>> out = source1
.map(new IdMap()).setParallelism(DEFAULT_PARALLELISM+1)
.join(source2).where("*").equalTo("*")
.writeAsText("/some/newpath");
Plan plan = env.createProgramPlan();
// submit the plan to the compiler
OptimizedPlan oPlan = compileNoStats(plan);
}
示例3: testNestedAggregate
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testNestedAggregate() throws Exception {
/*
* Nested Aggregate
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple1<Integer>> aggregateDs = ds.groupBy(1)
.aggregate(Aggregations.MIN, 0)
.aggregate(Aggregations.MIN, 0)
.project(0);
List<Tuple1<Integer>> result = aggregateDs.collect();
String expected = "1\n";
compareResultAsTuples(result, expected);
}
示例4: testCorrectnessOfDistinctOnTuplesWithKeyExtractorFunction
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testCorrectnessOfDistinctOnTuplesWithKeyExtractorFunction() throws Exception {
/*
* check correctness of distinct on tuples with key extractor function
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds = CollectionDataSets.getSmall5TupleDataSet(env);
DataSet<Tuple1<Integer>> reduceDs = ds.union(ds).distinct(new KeySelector1()).project(0);
List<Tuple1<Integer>> result = reduceDs.collect();
String expected = "1\n" + "2\n";
compareResultAsTuples(result, expected);
}
示例5: testCorrectnessOfDistinctOnTuplesWithFieldExpressions
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testCorrectnessOfDistinctOnTuplesWithFieldExpressions() throws Exception {
/*
* check correctness of distinct on tuples with field expressions
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds = CollectionDataSets.getSmall5TupleDataSet(env);
DataSet<Tuple1<Integer>> reduceDs = ds.union(ds).distinct("f0").project(0);
List<Tuple1<Integer>> result = reduceDs.collect();
String expected = "1\n" +
"2\n";
compareResultAsTuples(result, expected);
}
示例6: copyFromLocal
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
public static void copyFromLocal(final File localPath,
final URI remotePath) throws Exception {
// Do it in another Thread because HDFS can deadlock if being interrupted while copying
String threadName = "HDFS Copy from " + localPath + " to " + remotePath;
final Tuple1<Exception> asyncException = Tuple1.of(null);
Thread copyThread = new Thread(threadName) {
@Override
public void run() {
try {
Configuration hadoopConf = HadoopFileSystem.getHadoopConfiguration();
FileSystem fs = FileSystem.get(remotePath, hadoopConf);
fs.copyFromLocalFile(new Path(localPath.getAbsolutePath()),
new Path(remotePath));
} catch (Exception t) {
asyncException.f0 = t;
}
}
};
copyThread.setDaemon(true);
copyThread.start();
copyThread.join();
if (asyncException.f0 != null) {
throw asyncException.f0;
}
}
示例7: testSortPartitionByKeyField
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testSortPartitionByKeyField() throws Exception {
/*
* Test sort partition on key field
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(4);
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
List<Tuple1<Boolean>> result = ds
.map(new IdMapper<Tuple3<Integer, Long, String>>()).setParallelism(4) // parallelize input
.sortPartition(1, Order.DESCENDING)
.mapPartition(new OrderCheckMapper<>(new Tuple3Checker()))
.distinct().collect();
String expected = "(true)\n";
compareResultAsText(result, expected);
}
示例8: testSortPartitionByTwoKeyFields
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testSortPartitionByTwoKeyFields() throws Exception {
/*
* Test sort partition on two key fields
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(2);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds = CollectionDataSets.get5TupleDataSet(env);
List<Tuple1<Boolean>> result = ds
.map(new IdMapper<Tuple5<Integer, Long, Integer, String, Long>>()).setParallelism(2) // parallelize input
.sortPartition(4, Order.ASCENDING)
.sortPartition(2, Order.DESCENDING)
.mapPartition(new OrderCheckMapper<>(new Tuple5Checker()))
.distinct().collect();
String expected = "(true)\n";
compareResultAsText(result, expected);
}
示例9: testSortPartitionByTwoFieldExpressions
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testSortPartitionByTwoFieldExpressions() throws Exception {
/*
* Test sort partition on two field expressions
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(2);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds = CollectionDataSets.get5TupleDataSet(env);
List<Tuple1<Boolean>> result = ds
.map(new IdMapper<Tuple5<Integer, Long, Integer, String, Long>>()).setParallelism(2) // parallelize input
.sortPartition("f4", Order.ASCENDING)
.sortPartition("f2", Order.DESCENDING)
.mapPartition(new OrderCheckMapper<>(new Tuple5Checker()))
.distinct().collect();
String expected = "(true)\n";
compareResultAsText(result, expected);
}
示例10: testSortPartitionWithKeySelector1
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testSortPartitionWithKeySelector1() throws Exception {
/*
* Test sort partition on an extracted key
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(4);
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
List<Tuple1<Boolean>> result = ds
.map(new IdMapper<Tuple3<Integer, Long, String>>()).setParallelism(4) // parallelize input
.sortPartition(new KeySelector<Tuple3<Integer, Long, String>, Long>() {
@Override
public Long getKey(Tuple3<Integer, Long, String> value) throws Exception {
return value.f1;
}
}, Order.ASCENDING)
.mapPartition(new OrderCheckMapper<>(new Tuple3AscendingChecker()))
.distinct().collect();
String expected = "(true)\n";
compareResultAsText(result, expected);
}
示例11: testProgram
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Override
protected void testProgram() throws Exception {
// set up execution environment
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
// read vertex and edge data
DataSet<Tuple1<Long>> vertices = env.readCsvFile(verticesPath).types(Long.class);
DataSet<Tuple2<Long, Long>> edges = env.readCsvFile(edgesPath).fieldDelimiter(" ").types(Long.class, Long.class)
.flatMap(new ConnectedComponents.UndirectEdge());
// assign the initial components (equal to the vertex id)
DataSet<Tuple2<Long, Long>> verticesWithInitialId = vertices.map(new DuplicateValue<Long>());
// open a delta iteration
DeltaIteration<Tuple2<Long, Long>, Tuple2<Long, Long>> iteration =
verticesWithInitialId.iterateDelta(verticesWithInitialId, 100, 0);
// apply the step logic: join with the edges, select the minimum neighbor, update if the component of the candidate is smaller
DataSet<Tuple2<Long, Long>> changes = iteration.getWorkset().join(edges).where(0).equalTo(0).with(new ConnectedComponents.NeighborWithComponentIDJoin())
.groupBy(0).aggregate(Aggregations.MIN, 1)
.join(iteration.getSolutionSet()).where(0).equalTo(0)
.with(new ConnectedComponents.ComponentIdFilter());
// close the delta iteration (delta and new workset are identical)
DataSet<Tuple2<Long, Long>> result = iteration.closeWith(changes, changes);
result.writeAsCsv(resultPath, "\n", " ");
// execute program
env.execute("Connected Components Example");
}
示例12: checkJoinWithReplicatedSourceInputBehindRebalance
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
/**
* Tests compiler fail for join program with replicated data source behind rebalance.
*/
@Test(expected = CompilerException.class)
public void checkJoinWithReplicatedSourceInputBehindRebalance() {
ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();
env.setParallelism(DEFAULT_PARALLELISM);
TupleTypeInfo<Tuple1<String>> typeInfo = TupleTypeInfo.getBasicTupleTypeInfo(String.class);
ReplicatingInputFormat<Tuple1<String>, FileInputSplit> rif =
new ReplicatingInputFormat<Tuple1<String>, FileInputSplit>(new TupleCsvInputFormat<Tuple1<String>>(new Path("/some/path"), typeInfo));
DataSet<Tuple1<String>> source1 = env.createInput(rif, new TupleTypeInfo<Tuple1<String>>(BasicTypeInfo.STRING_TYPE_INFO));
DataSet<Tuple1<String>> source2 = env.readCsvFile("/some/otherpath").types(String.class);
DataSink<Tuple2<Tuple1<String>, Tuple1<String>>> out = source1
.rebalance()
.join(source2).where("*").equalTo("*")
.writeAsText("/some/newpath");
Plan plan = env.createProgramPlan();
// submit the plan to the compiler
OptimizedPlan oPlan = compileNoStats(plan);
}
示例13: testCorrectnessOfDistinctOnCustomTypeWithTypeExtractor
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@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);
}
示例14: testSortPartitionByFieldExpression
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSortPartitionByFieldExpression() throws Exception {
/*
* Test sort partition on field expression
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(4);
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
List<Tuple1<Boolean>> result = ds
.map(new IdMapper()).setParallelism(4) // parallelize input
.sortPartition("f1", Order.DESCENDING)
.mapPartition(new OrderCheckMapper<>(new Tuple3Checker()))
.distinct().collect();
String expected = "(true)\n";
compareResultAsText(result, expected);
}
示例15: testSortPartitionByNestedFieldExpression
import org.apache.flink.api.java.tuple.Tuple1; //导入依赖的package包/类
@Test
public void testSortPartitionByNestedFieldExpression() throws Exception {
/*
* Test sort partition on nested field expressions
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(3);
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds = CollectionDataSets.getGroupSortedNestedTupleDataSet(env);
List<Tuple1<Boolean>> result = ds
.map(new IdMapper<Tuple2<Tuple2<Integer, Integer>, String>>()).setParallelism(3) // parallelize input
.sortPartition("f0.f1", Order.ASCENDING)
.sortPartition("f1", Order.DESCENDING)
.mapPartition(new OrderCheckMapper<>(new NestedTupleChecker()))
.distinct().collect();
String expected = "(true)\n";
compareResultAsText(result, expected);
}