本文整理汇总了Java中org.apache.flink.api.java.DataSet.cross方法的典型用法代码示例。如果您正苦于以下问题:Java DataSet.cross方法的具体用法?Java DataSet.cross怎么用?Java DataSet.cross使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.java.DataSet
的用法示例。
在下文中一共展示了DataSet.cross方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAdvanced
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testAdvanced() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.getConfig().disableObjectReuse();
DataSet<Integer> data = env.fromElements(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
DataSet<Integer> data2 = env.fromElements(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
DataSet<Tuple2<Integer, Integer>> data3 = data.cross(data2);
// count
long numEntries = data3.count();
assertEquals(100, numEntries);
// collect
ArrayList<Tuple2<Integer, Integer>> list = (ArrayList<Tuple2<Integer, Integer>>) data3.collect();
// set expected entries in a hash map to true
HashMap<Tuple2<Integer, Integer>, Boolean> expected = new HashMap<Tuple2<Integer, Integer>, Boolean>();
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
expected.put(new Tuple2<Integer, Integer>(i, j), true);
}
}
// check if all entries are contained in the hash map
for (int i = 0; i < 100; i++) {
Tuple2<Integer, Integer> element = list.get(i);
assertEquals(expected.get(element), true);
expected.remove(element);
}
}
示例2: testCorrectnessOfDefaultCross
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testCorrectnessOfDefaultCross() throws Exception {
/*
* check correctness of default cross
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.getSmall5TupleDataSet(env);
DataSet<Tuple2<Tuple3<Integer, Long, String>, Tuple5<Integer, Long, Integer, String, Long>>> crossDs = ds.cross(ds2);
List<Tuple2<Tuple3<Integer, Long, String>, Tuple5<Integer, Long, Integer, String, Long>>> result = crossDs.collect();
String expected = "(1,1,Hi),(2,2,1,Hallo Welt,2)\n"
+
"(1,1,Hi),(1,1,0,Hallo,1)\n" +
"(1,1,Hi),(2,3,2,Hallo Welt wie,1)\n" +
"(2,2,Hello),(2,2,1,Hallo Welt,2)\n" +
"(2,2,Hello),(1,1,0,Hallo,1)\n" +
"(2,2,Hello),(2,3,2,Hallo Welt wie,1)\n" +
"(3,2,Hello world),(2,2,1,Hallo Welt,2)\n" +
"(3,2,Hello world),(1,1,0,Hallo,1)\n" +
"(3,2,Hello world),(2,3,2,Hallo Welt wie,1)\n";
compareResultAsTuples(result, expected);
}
示例3: createCrossOperation
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
private <IN1, IN2, OUT> void createCrossOperation(DatasizeHint mode, PythonOperationInfo info, TypeInformation<OUT> type) {
DataSet<IN1> op1 = sets.getDataSet(info.parentID);
DataSet<IN2> op2 = sets.getDataSet(info.otherID);
DefaultCross<IN1, IN2> defaultResult;
switch (mode) {
case NONE:
defaultResult = op1.cross(op2);
break;
case HUGE:
defaultResult = op1.crossWithHuge(op2);
break;
case TINY:
defaultResult = op1.crossWithTiny(op2);
break;
default:
throw new IllegalArgumentException("Invalid Cross mode specified: " + mode);
}
defaultResult.setParallelism(info.parallelism);
if (info.usesUDF) {
sets.add(info.setID, defaultResult
.mapPartition(new PythonMapPartition<Tuple2<IN1, IN2>, OUT>(operatorConfig, info.envID, info.setID, type))
.setParallelism(info.parallelism).name(info.name));
} else {
sets.add(info.setID, defaultResult.name("DefaultCross"));
}
}