Java Code Examples for org.apache.flink.api.java.tuple.Tuple5

The following examples show how to use org.apache.flink.api.java.tuple.Tuple5. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Author: ljygz   File: AggregateOperatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAggregationTypes() {
	try {
		final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
		DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);

		// should work: multiple aggregates
		tupleDs.aggregate(Aggregations.SUM, 0).and(Aggregations.MIN, 4);

		// should work: nested aggregates
		tupleDs.aggregate(Aggregations.MIN, 2).aggregate(Aggregations.SUM, 1);

		// should not work: average on string
		try {
			tupleDs.aggregate(Aggregations.SUM, 2);
			Assert.fail();
		} catch (UnsupportedAggregationTypeException iae) {
			// we're good here
		}
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #2
Source Project: flink   Author: flink-tpc-ds   File: CoGroupITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupWithMultipleKeyFieldsWithFieldSelector() throws Exception {
	/*
	 * CoGroup with multiple key fields
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds1 = CollectionDataSets.get5TupleDataSet(env);
	DataSet<Tuple3<Integer, Long, String>> ds2 = CollectionDataSets.get3TupleDataSet(env);

	DataSet<Tuple3<Integer, Long, String>> coGrouped = ds1.coGroup(ds2).
			where(0, 4).equalTo(0, 1).with(new Tuple5Tuple3CoGroup());

	List<Tuple3<Integer, Long, String>> result = coGrouped.collect();

	String expected = "1,1,Hallo\n" +
			"2,2,Hallo Welt\n" +
			"3,2,Hallo Welt wie gehts?\n" +
			"3,2,ABC\n" +
			"5,3,HIJ\n" +
			"5,3,IJK\n";

	compareResultAsTuples(result, expected);
}
 
Example #3
Source Project: Flink-CEPplus   Author: ljygz   File: JoinITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultJoinOnTuples() throws Exception {
	/*
	 * Default Join on tuples
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
	DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
	DataSet<Tuple2<Tuple3<Integer, Long, String>, Tuple5<Integer, Long, Integer, String, Long>>> joinDs =
			ds1.join(ds2)
					.where(0)
					.equalTo(2);

	List<Tuple2<Tuple3<Integer, Long, String>, Tuple5<Integer, Long, Integer, String, Long>>> result = joinDs.collect();

	String expected = "(1,1,Hi),(2,2,1,Hallo Welt,2)\n" +
			"(2,2,Hello),(2,3,2,Hallo Welt wie,1)\n" +
			"(3,2,Hello world),(3,4,3,Hallo Welt wie gehts?,2)\n";

	compareResultAsTuples(result, expected);

}
 
Example #4
Source Project: Flink-CEPplus   Author: ljygz   File: JoinITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinThatReturnsTheRightInputObject() throws Exception {
	/*
	 * Join that returns the right input object
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
	DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
	DataSet<Tuple5<Integer, Long, Integer, String, Long>> joinDs =
			ds1.join(ds2)
					.where(1)
					.equalTo(1)
					.with(new RightReturningJoin());

	List<Tuple5<Integer, Long, Integer, String, Long>> result = joinDs.collect();

	String expected = "1,1,0,Hallo,1\n" +
			"2,2,1,Hallo Welt,2\n" +
			"2,2,1,Hallo Welt,2\n";

	compareResultAsTuples(result, expected);
}
 
Example #5
Source Project: Flink-CEPplus   Author: ljygz   File: ValueCollectionDataSets.java    License: Apache License 2.0 6 votes vote down vote up
public static DataSet<Tuple5<IntValue, LongValue, IntValue, StringValue, LongValue>> getSmall5TupleDataSet(ExecutionEnvironment env) {
	List<Tuple5<IntValue, LongValue, IntValue, StringValue, LongValue>> data = new ArrayList<>();

	data.add(new Tuple5<>(new IntValue(1), new LongValue(1L), new IntValue(0), new StringValue("Hallo"), new LongValue(1L)));
	data.add(new Tuple5<>(new IntValue(2), new LongValue(2L), new IntValue(1), new StringValue("Hallo Welt"), new LongValue(2L)));
	data.add(new Tuple5<>(new IntValue(2), new LongValue(3L), new IntValue(2), new StringValue("Hallo Welt wie"), new LongValue(1L)));

	Collections.shuffle(data);

	TupleTypeInfo<Tuple5<IntValue, LongValue, IntValue, StringValue, LongValue>> type = new
		TupleTypeInfo<>(
			ValueTypeInfo.INT_VALUE_TYPE_INFO,
			ValueTypeInfo.LONG_VALUE_TYPE_INFO,
			ValueTypeInfo.INT_VALUE_TYPE_INFO,
			ValueTypeInfo.STRING_VALUE_TYPE_INFO,
			ValueTypeInfo.LONG_VALUE_TYPE_INFO
	);

	return env.fromCollection(data, type);
}
 
Example #6
Source Project: Flink-CEPplus   Author: ljygz   File: DataSinkTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTupleTwoOrderExp() {

	final ExecutionEnvironment env = ExecutionEnvironment
			.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env
			.fromCollection(emptyTupleData, tupleTypeInfo);

	// should work
	try {
		tupleDs.writeAsText("/tmp/willNotHappen")
			.sortLocalOutput("f1", Order.ASCENDING)
			.sortLocalOutput("f4", Order.DESCENDING);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example #7
Source Project: Flink-CEPplus   Author: ljygz   File: DataSinkTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTupleSingleOrderExp() {

	final ExecutionEnvironment env = ExecutionEnvironment
			.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env
			.fromCollection(emptyTupleData, tupleTypeInfo);

	// should work
	try {
		tupleDs.writeAsText("/tmp/willNotHappen")
			.sortLocalOutput("f0", Order.ANY);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example #8
Source Project: Flink-CEPplus   Author: ljygz   File: CrossITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectnessOfCrossIfUDFReturnsLeftInputObject() throws Exception {
	/*
	 * check correctness of cross if UDF returns left input object
	 */

	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<Tuple3<Integer, Long, String>> crossDs = ds.cross(ds2).with(new Tuple3ReturnLeft());

	List<Tuple3<Integer, Long, String>> result = crossDs.collect();

	String expected = "1,1,Hi\n" +
			"1,1,Hi\n" +
			"1,1,Hi\n" +
			"2,2,Hello\n" +
			"2,2,Hello\n" +
			"2,2,Hello\n" +
			"3,2,Hello world\n" +
			"3,2,Hello world\n" +
			"3,2,Hello world\n";

	compareResultAsTuples(result, expected);
}
 
Example #9
Source Project: Flink-CEPplus   Author: ljygz   File: GroupReduceITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTupleKeySelectorSortCombineOnTuple() throws Exception {
	/*
	 * check correctness of sorted groupReduceon with Tuple2 keyselector sorting
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(1);

	DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds = CollectionDataSets.get5TupleDataSet(env);
	DataSet<Tuple5<Integer, Long, Integer, String, Long>> reduceDs = ds
			.groupBy(new IntFieldExtractor<Tuple5<Integer, Long, Integer, String, Long>>(0))
			.sortGroup(new FiveToTwoTupleExtractor(), Order.DESCENDING)
			.reduceGroup(new Tuple5SortedGroupReduce());

	List<Tuple5<Integer, Long, Integer, String, Long>> result = reduceDs.collect();

	String expected = "1,1,0,Hallo,1\n"
			+
			"2,5,0,Hallo Welt-Hallo Welt wie,1\n" +
			"3,15,0,BCD-ABC-Hallo Welt wie gehts?,2\n" +
			"4,34,0,FGH-CDE-EFG-DEF,1\n" +
			"5,65,0,IJK-HIJ-KLM-JKL-GHI,1\n";

	compareResultAsTuples(result, expected);
}
 
Example #10
Source Project: Flink-CEPplus   Author: ljygz   File: GroupReduceITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(
		Iterable<Tuple5<Integer, Long, Integer, String, Long>> values,
		Collector<Tuple5<Integer, Long, Integer, String, Long>> out) {
	int i = 0;
	long l = 0L;
	long l2 = 0L;

	for (Tuple5<Integer, Long, Integer, String, Long> t : values) {
		i = t.f0;
		l += t.f1;
		l2 = t.f4;
	}

	out.collect(new Tuple5<>(i, l, 0, "P-)", l2));
}
 
Example #11
Source Project: Flink-CEPplus   Author: ljygz   File: JoinOperatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testJoinKeyMixing3() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<CustomType> ds2 = env.fromCollection(customTypeData);

	// should not work, incompatible types
	ds1.join(ds2)
	.where(2)
	.equalTo(
			new KeySelector<CustomType, Long>() {

					@Override
					public Long getKey(CustomType value) {
						return value.myLong;
					}
				}
			);
}
 
Example #12
Source Project: flink   Author: flink-tpc-ds   File: CoGroupOperatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testCoGroupKeyMixing4() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<CustomType> ds2 = env.fromCollection(customTypeData);

	// should not work, more than one key field position
	ds1.coGroup(ds2)
	.where(1, 3)
	.equalTo(
			new KeySelector<CustomType, Long>() {

					@Override
					public Long getKey(CustomType value) {
						return value.myLong;
					}
				}
			);
}
 
Example #13
Source Project: flink   Author: flink-tpc-ds   File: CrossOperatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCrossProjection27() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should work
	try {
		ds1.cross(ds2)
			.projectSecond()
			.projectFirst(1, 4);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example #14
Source Project: Flink-CEPplus   Author: ljygz   File: CoGroupITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupWithBroadcastSet() throws Exception {
	/*
	 * Reduce with broadcast set
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Integer> intDs = CollectionDataSets.getIntegerDataSet(env);

	DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds = CollectionDataSets.get5TupleDataSet(env);
	DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
	DataSet<Tuple3<Integer, Integer, Integer>> coGroupDs = ds.coGroup(ds2).where(0).equalTo(0).with(new Tuple5CoGroupBC()).withBroadcastSet(intDs, "ints");

	List<Tuple3<Integer, Integer, Integer>> result = coGroupDs.collect();

	String expected = "1,0,55\n" +
			"2,6,55\n" +
			"3,24,55\n" +
			"4,60,55\n" +
			"5,120,55\n";

	compareResultAsTuples(result, expected);
}
 
Example #15
Source Project: flink   Author: flink-tpc-ds   File: CrossOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testCrossProjection14() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should not work, index out of range
	ds1.cross(ds2)
		.projectFirst(0)
		.projectSecond(5);
}
 
Example #16
Source Project: flink   Author: flink-tpc-ds   File: DistinctOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDistinctByKeyFields1() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should work
	try {
		tupleDs.distinct(0);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example #17
Source Project: Flink-CEPplus   Author: ljygz   File: LeftOuterJoinOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLeftOuter4() {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should work
	ds1.leftOuterJoin(ds2)
			.where(0).equalTo(new IntKeySelector())
			.with(new DummyJoin());
}
 
Example #18
Source Project: Flink-CEPplus   Author: ljygz   File: JavaSqlITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testUnion() throws Exception {
	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
	StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
	StreamITCase.clear();

	DataStream<Tuple3<Integer, Long, String>> ds1 = JavaStreamTestData.getSmall3TupleDataSet(env);
	Table t1 = tableEnv.fromDataStream(ds1, "a,b,c");
	tableEnv.registerTable("T1", t1);

	DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds2 = JavaStreamTestData.get5TupleDataStream(env);
	tableEnv.registerDataStream("T2", ds2, "a, b, d, c, e");

	String sqlQuery = "SELECT * FROM T1 " +
						"UNION ALL " +
						"(SELECT a, b, c FROM T2 WHERE a	< 3)";
	Table result = tableEnv.sqlQuery(sqlQuery);

	DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class);
	resultSet.addSink(new StreamITCase.StringSink<Row>());
	env.execute();

	List<String> expected = new ArrayList<>();
	expected.add("1,1,Hi");
	expected.add("2,2,Hello");
	expected.add("3,2,Hello world");
	expected.add("1,1,Hallo");
	expected.add("2,2,Hallo Welt");
	expected.add("2,3,Hallo Welt wie");

	StreamITCase.compareWithList(expected);
}
 
Example #19
Source Project: Flink-CEPplus   Author: ljygz   File: GroupCombineOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSemanticPropsWithKeySelector7() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);

	GroupCombineOperator<Tuple5<Integer, Long, String, Long, Integer>, Tuple5<Integer, Long, String, Long, Integer>> combineOp =
			tupleDs.groupBy(new DummyTestKeySelector())
					.combineGroup(new DummyGroupCombineFunction4());

	SemanticProperties semProps = combineOp.getSemanticProperties();

	assertTrue(semProps.getForwardingTargetFields(0, 0).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 1).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 2).size() == 1);
	assertTrue(semProps.getForwardingTargetFields(0, 2).contains(0));
	assertTrue(semProps.getForwardingTargetFields(0, 3).size() == 1);
	assertTrue(semProps.getForwardingTargetFields(0, 3).contains(1));
	assertTrue(semProps.getForwardingTargetFields(0, 4).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 5).size() == 1);
	assertTrue(semProps.getForwardingTargetFields(0, 5).contains(3));
	assertTrue(semProps.getForwardingTargetFields(0, 6).size() == 0);

	assertTrue(semProps.getForwardingSourceField(0, 0) == 2);
	assertTrue(semProps.getForwardingSourceField(0, 1) == 3);
	assertTrue(semProps.getForwardingSourceField(0, 2) < 0);
	assertTrue(semProps.getForwardingSourceField(0, 3) == 5);
	assertTrue(semProps.getForwardingSourceField(0, 4) < 0);

	assertTrue(semProps.getReadFields(0) == null);
}
 
Example #20
Source Project: Flink-CEPplus   Author: ljygz   File: SelectByFunctionsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test cases checks when two tuples only differ in one value, but this value is not
 * in the fields list. In that case it should be seen as equal and then the first given tuple (value1) should be returned by reduce().
 */
@Test
public void testMinByComparisonSpecialCase1() {
	SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>> minByTuple = new SelectByMinFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 3});

	try {
		Assert.assertSame("SelectByMin must return the first given tuple", specialCaseBigger, minByTuple.reduce(specialCaseBigger, bigger));
		Assert.assertSame("SelectByMin must return the first given tuple", bigger, minByTuple.reduce(bigger, specialCaseBigger));
	} catch (Exception e) {
		Assert.fail("No exception should be thrown while comparing both tuples");
	}
}
 
Example #21
Source Project: flink   Author: flink-tpc-ds   File: JoinOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testJoinProjection1() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should work
	try {
		ds1.join(ds2).where(0).equalTo(0)
		.projectFirst(0);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example #22
Source Project: flink   Author: flink-tpc-ds   File: ValueCollectionDataSets.java    License: Apache License 2.0 5 votes vote down vote up
public static DataSet<Tuple5<IntValue, LongValue, IntValue, StringValue, LongValue>> get5TupleDataSet(ExecutionEnvironment env) {
	List<Tuple5<IntValue, LongValue, IntValue, StringValue, LongValue>> data = new ArrayList<>();

	data.add(new Tuple5<>(new IntValue(1), new LongValue(1L), new IntValue(0), new StringValue("Hallo"), new LongValue(1L)));
	data.add(new Tuple5<>(new IntValue(2), new LongValue(2L), new IntValue(1), new StringValue("Hallo Welt"), new LongValue(2L)));
	data.add(new Tuple5<>(new IntValue(2), new LongValue(3L), new IntValue(2), new StringValue("Hallo Welt wie"), new LongValue(1L)));
	data.add(new Tuple5<>(new IntValue(3), new LongValue(4L), new IntValue(3), new StringValue("Hallo Welt wie gehts?"), new LongValue(2L)));
	data.add(new Tuple5<>(new IntValue(3), new LongValue(5L), new IntValue(4), new StringValue("ABC"), new LongValue(2L)));
	data.add(new Tuple5<>(new IntValue(3), new LongValue(6L), new IntValue(5), new StringValue("BCD"), new LongValue(3L)));
	data.add(new Tuple5<>(new IntValue(4), new LongValue(7L), new IntValue(6), new StringValue("CDE"), new LongValue(2L)));
	data.add(new Tuple5<>(new IntValue(4), new LongValue(8L), new IntValue(7), new StringValue("DEF"), new LongValue(1L)));
	data.add(new Tuple5<>(new IntValue(4), new LongValue(9L), new IntValue(8), new StringValue("EFG"), new LongValue(1L)));
	data.add(new Tuple5<>(new IntValue(4), new LongValue(10L), new IntValue(9), new StringValue("FGH"), new LongValue(2L)));
	data.add(new Tuple5<>(new IntValue(5), new LongValue(11L), new IntValue(10), new StringValue("GHI"), new LongValue(1L)));
	data.add(new Tuple5<>(new IntValue(5), new LongValue(12L), new IntValue(11), new StringValue("HIJ"), new LongValue(3L)));
	data.add(new Tuple5<>(new IntValue(5), new LongValue(13L), new IntValue(12), new StringValue("IJK"), new LongValue(3L)));
	data.add(new Tuple5<>(new IntValue(5), new LongValue(14L), new IntValue(13), new StringValue("JKL"), new LongValue(2L)));
	data.add(new Tuple5<>(new IntValue(5), new LongValue(15L), new IntValue(14), new StringValue("KLM"), new LongValue(2L)));

	Collections.shuffle(data);

	TupleTypeInfo<Tuple5<IntValue, LongValue, IntValue, StringValue, LongValue>> type = new
		TupleTypeInfo<>(
			ValueTypeInfo.INT_VALUE_TYPE_INFO,
			ValueTypeInfo.LONG_VALUE_TYPE_INFO,
			ValueTypeInfo.INT_VALUE_TYPE_INFO,
			ValueTypeInfo.STRING_VALUE_TYPE_INFO,
			ValueTypeInfo.LONG_VALUE_TYPE_INFO
	);

	return env.fromCollection(data, type);
}
 
Example #23
Source Project: flink   Author: flink-tpc-ds   File: ReduceOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSemanticPropsWithKeySelector2() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);

	ReduceOperator<Tuple5<Integer, Long, String, Long, Integer>> reduceOp =
			tupleDs.groupBy(new DummyTestKeySelector())
					.reduce(new DummyReduceFunction2())
						.withForwardedFields("0->4;1;1->3;2");

	SemanticProperties semProps = reduceOp.getSemanticProperties();

	assertTrue(semProps.getForwardingTargetFields(0, 0).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 1).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 2).size() == 1);
	assertTrue(semProps.getForwardingTargetFields(0, 2).contains(4));
	assertTrue(semProps.getForwardingTargetFields(0, 3).size() == 2);
	assertTrue(semProps.getForwardingTargetFields(0, 3).contains(1));
	assertTrue(semProps.getForwardingTargetFields(0, 3).contains(3));
	assertTrue(semProps.getForwardingTargetFields(0, 4).size() == 1);
	assertTrue(semProps.getForwardingTargetFields(0, 4).contains(2));
	assertTrue(semProps.getForwardingTargetFields(0, 5).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 6).size() == 0);

	assertTrue(semProps.getForwardingSourceField(0, 0) < 0);
	assertTrue(semProps.getForwardingSourceField(0, 1) == 3);
	assertTrue(semProps.getForwardingSourceField(0, 2) == 4);
	assertTrue(semProps.getForwardingSourceField(0, 3) == 3);
	assertTrue(semProps.getForwardingSourceField(0, 4) == 2);

	assertTrue(semProps.getReadFields(0).size() == 3);
	assertTrue(semProps.getReadFields(0).contains(2));
	assertTrue(semProps.getReadFields(0).contains(5));
	assertTrue(semProps.getReadFields(0).contains(6));
}
 
Example #24
Source Project: flink   Author: flink-tpc-ds   File: JoinOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testJoinProjection29() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should not work, index out of range
	ds1.join(ds2).where(0).equalTo(0)
	.projectSecond(5);
}
 
Example #25
Source Project: Flink-CEPplus   Author: ljygz   File: RightOuterJoinOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = CompositeType.InvalidFieldReferenceException.class)
public void testRightOuter8() {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// invalid key reference
	ds1.rightOuterJoin(ds2)
			.where(1).equalTo("f5")
			.with(new DummyJoin());
}
 
Example #26
Source Project: flink   Author: flink-tpc-ds   File: CrossOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testCrossProjection8() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyTupleData, tupleTypeInfo);
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should not work, index out of range
	ds1.cross(ds2)
		.projectFirst(5);
}
 
Example #27
Source Project: flink   Author: flink-tpc-ds   File: ReduceITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testReduceATupleReturningKeySelector() throws Exception {
	/*
	 * Reduce with a Tuple-returning KeySelector
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple5<Integer, Long,  Integer, String, Long>> ds = CollectionDataSets.get5TupleDataSet(env);
	DataSet<Tuple5<Integer, Long,  Integer, String, Long>> reduceDs = ds
			.groupBy(new KeySelector3()).reduce(new Tuple5Reduce());

	List<Tuple5<Integer, Long, Integer, String, Long>> result = reduceDs
			.collect();

	String expected = "1,1,0,Hallo,1\n" +
			"2,3,2,Hallo Welt wie,1\n" +
			"2,2,1,Hallo Welt,2\n" +
			"3,9,0,P-),2\n" +
			"3,6,5,BCD,3\n" +
			"4,17,0,P-),1\n" +
			"4,17,0,P-),2\n" +
			"5,11,10,GHI,1\n" +
			"5,29,0,P-),2\n" +
			"5,25,0,P-),3\n";

	compareResultAsTuples(result, expected);
}
 
Example #28
Source Project: Flink-CEPplus   Author: ljygz   File: ReduceOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSemanticPropsWithKeySelector1() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);

	ReduceOperator<Tuple5<Integer, Long, String, Long, Integer>> reduceOp =
			tupleDs.groupBy(new DummyTestKeySelector())
					.reduce(new DummyReduceFunction1());

	SemanticProperties semProps = reduceOp.getSemanticProperties();

	assertTrue(semProps.getForwardingTargetFields(0, 0).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 1).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 2).size() == 1);
	assertTrue(semProps.getForwardingTargetFields(0, 2).contains(4));
	assertTrue(semProps.getForwardingTargetFields(0, 3).size() == 2);
	assertTrue(semProps.getForwardingTargetFields(0, 3).contains(1));
	assertTrue(semProps.getForwardingTargetFields(0, 3).contains(3));
	assertTrue(semProps.getForwardingTargetFields(0, 4).size() == 1);
	assertTrue(semProps.getForwardingTargetFields(0, 4).contains(2));
	assertTrue(semProps.getForwardingTargetFields(0, 5).size() == 0);
	assertTrue(semProps.getForwardingTargetFields(0, 6).size() == 0);

	assertTrue(semProps.getForwardingSourceField(0, 0) < 0);
	assertTrue(semProps.getForwardingSourceField(0, 1) == 3);
	assertTrue(semProps.getForwardingSourceField(0, 2) == 4);
	assertTrue(semProps.getForwardingSourceField(0, 3) == 3);
	assertTrue(semProps.getForwardingSourceField(0, 4) == 2);

	assertTrue(semProps.getReadFields(0).size() == 3);
	assertTrue(semProps.getReadFields(0).contains(2));
	assertTrue(semProps.getReadFields(0).contains(5));
	assertTrue(semProps.getReadFields(0).contains(6));
}
 
Example #29
Source Project: flink   Author: flink-tpc-ds   File: MaxByOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test validates that an index which is out of bounds throws an
 * IndexOutOfBoundsException.
 */
@Test(expected = IndexOutOfBoundsException.class)
public void testOutOfTupleBoundsDataset3() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should not work, key out of tuple bounds
	tupleDs.maxBy(1, 2, 3, 4, -1);
}
 
Example #30
Source Project: Flink-CEPplus   Author: ljygz   File: MinByOperatorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test validates that an index which is out of bounds throws an
 * IndexOutOfBoundsException.
 */
@Test(expected = IndexOutOfBoundsException.class)
public void testOutOfTupleBoundsDataset1() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Tuple5<Integer, Long, String, Long, Integer>> tupleDs = env.fromCollection(emptyTupleData, tupleTypeInfo);

	// should not work, key out of tuple bounds
	tupleDs.minBy(5);
}