Java Code Examples for org.apache.flink.api.java.DataSet#cross()

The following examples show how to use org.apache.flink.api.java.DataSet#cross() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CountCollectITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 2
Source File: CrossITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: PythonPlanBinder.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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"));
	}
}
 
Example 4
Source File: CountCollectITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 5
Source File: CrossITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: CountCollectITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 7
Source File: CrossITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
}