org.apache.flink.api.java.tuple.Tuple7 Java Examples

The following examples show how to use org.apache.flink.api.java.tuple.Tuple7. 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: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithNestedKeyExpression2() throws Exception {
	/*
	 * Join nested pojo against tuple (selected as an integer)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedPojo.longNumber")
					.equalTo(6) // <--- difference!
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

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

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #2
Source File: CoGroupITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupFieldSelectorAndKeySelector() throws Exception {
	/*
	 * CoGroup field-selector (expression keys) + key selector function
	 * The key selector is simple here
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<CustomType> coGroupDs = ds.coGroup(ds2)
			.where(new KeySelector1()).equalTo(6).with(new CoGroup2());

	List<CustomType> result = coGroupDs.collect();

	String expected = "-1,20000,Flink\n" +
			"-1,10000,Flink\n" +
			"-1,30000,Flink\n";

	compareResultAsText(result, expected);
}
 
Example #3
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedIntoTuple() throws Exception {
	/*
	 * nested into tuple
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedPojo.longNumber", "number", "nestedTupleWithCustom.f0").equalTo("f6", "f0", "f2");

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #4
Source File: OuterJoinITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithCompositeKeyExpressions() throws Exception {
	/*
	 * selecting multiple fields using expression language
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedPojo.longNumber", "number", "str")
					.equalTo("f6", "f0", "f1")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #5
Source File: OuterJoinITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testFullPojoWithFullTuple() throws Exception {
	/*
	 * full pojo with full tuple
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Long, Integer, Integer, Long, String, Integer, String>> ds2 = CollectionDataSets.getSmallTuplebasedDataSetMatchingPojo(env);
	DataSet<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("*")
					.equalTo("*")
					.with(new ProjectBothFunction<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(10000,10,100,1000,One,1,First)\n" +
			"2 Second (20,200,2000,Two) 20000,(20000,20,200,2000,Two,2,Second)\n" +
			"3 Third (30,300,3000,Three) 30000,(30000,30,300,3000,Three,3,Third)\n";

	compareResultAsTuples(result, expected);
}
 
Example #6
Source File: OuterJoinITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedIntoTupleIntoPojo() throws Exception {
	/*
	 * nested into tuple into pojo
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedTupleWithCustom.f0", "nestedTupleWithCustom.f1.myInt", "nestedTupleWithCustom.f1.myLong")
					.equalTo("f2", "f3", "f4")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #7
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedIntoTupleIntoPojo() throws Exception {
	/*
	 * nested into tuple into pojo
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedTupleWithCustom.f0", "nestedTupleWithCustom.f1.myInt", "nestedTupleWithCustom.f1.myLong")
					.equalTo("f2", "f3", "f4")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #8
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithCompositeKeyExpressions() throws Exception {
	/*
	 * selecting multiple fields using expression language
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedPojo.longNumber", "number", "str")
					.equalTo("f6", "f0", "f1")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #9
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinNestedPojoAgainstTupleSelectedUsingString() throws Exception {
	/*
	 * Join nested pojo against tuple (selected using a string)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedPojo.longNumber").equalTo("f6");

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

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #10
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinNestedPojoAgainstTupleSelectedUsingInteger() throws Exception {
	/*
	 * Join nested pojo against tuple (selected as an integer)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedPojo.longNumber").equalTo(6); // <--- difference!

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

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #11
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectingMultipleFieldsUsingExpressionLanguage() throws Exception {
	/*
	 * selecting multiple fields using expression language
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedPojo.longNumber", "number", "str").equalTo("f6", "f0", "f1");

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #12
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testFullPojoWithFullTuple() throws Exception {
	/*
	 * full pojo with full tuple
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Long, Integer, Integer, Long, String, Integer, String>> ds2 = CollectionDataSets.getSmallTuplebasedDataSetMatchingPojo(env);
	DataSet<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("*")
					.equalTo("*")
					.with(new ProjectBothFunction<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(10000,10,100,1000,One,1,First)\n" +
			"2 Second (20,200,2000,Two) 20000,(20000,20,200,2000,Two,2,Second)\n" +
			"3 Third (30,300,3000,Three) 30000,(30000,30,300,3000,Three,3,Third)\n";

	compareResultAsTuples(result, expected);
}
 
Example #13
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedIntoTupleIntoPojo() throws Exception {
	/*
	 * nested into tuple into pojo
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedTupleWithCustom.f0", "nestedTupleWithCustom.f1.myInt", "nestedTupleWithCustom.f1.myLong").equalTo("f2", "f3", "f4");

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #14
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testFullPojoWithFullTuple() throws Exception {
	/*
	 * full pojo with full tuple
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Long, Integer, Integer, Long, String, Integer, String>> ds2 = CollectionDataSets.getSmallTuplebasedDataSetMatchingPojo(env);
	DataSet<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> joinDs =
			ds1.join(ds2).where("*").equalTo("*");

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(10000,10,100,1000,One,1,First)\n" +
			"2 Second (20,200,2000,Two) 20000,(20000,20,200,2000,Two,2,Second)\n" +
			"3 Third (30,300,3000,Three) 30000,(30000,30,300,3000,Three,3,Third)\n";

	compareResultAsTuples(result, expected);
}
 
Example #15
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithNestedKeyExpression1() throws Exception {
	/*
	 * Join nested pojo against tuple (selected using a string)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedPojo.longNumber")
					.equalTo("f6")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

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

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #16
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedIntoTupleIntoPojo() throws Exception {
	/*
	 * nested into tuple into pojo
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedTupleWithCustom.f0", "nestedTupleWithCustom.f1.myInt", "nestedTupleWithCustom.f1.myLong")
					.equalTo("f2", "f3", "f4")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #17
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithCompositeKeyExpressions() throws Exception {
	/*
	 * selecting multiple fields using expression language
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedPojo.longNumber", "number", "str")
					.equalTo("f6", "f0", "f1")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #18
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithNestedKeyExpression1() throws Exception {
	/*
	 * Join nested pojo against tuple (selected using a string)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedPojo.longNumber")
					.equalTo("f6")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

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

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #19
Source File: OuterJoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedIntoTuple() throws Exception {
	/*
	 * nested into tuple
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.fullOuterJoin(ds2)
					.where("nestedPojo.longNumber", "number", "nestedTupleWithCustom.f0")
					.equalTo("f6", "f0", "f2")
					.with(new ProjectBothFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>());

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #20
Source File: CoGroupITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupOnTwoCustomTypeInputsWithExpressionKeyAndFieldSelector() throws
		Exception {
	/*
	 * CoGroup on two custom type inputs using expression keys
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<CustomType> coGroupDs = ds.coGroup(ds2)
			.where("nestedPojo.longNumber").equalTo(6).with(new CoGroup1());

	List<CustomType> result = coGroupDs.collect();

	String expected = 	"-1,20000,Flink\n" +
			"-1,10000,Flink\n" +
			"-1,30000,Flink\n";

	compareResultAsText(result, expected);
}
 
Example #21
Source File: CoGroupITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupFieldSelectorAndComplicatedKeySelector() throws Exception {
	/*
	 * CoGroup field-selector (expression keys) + key selector function
	 * The key selector is unnecessary complicated (Tuple1) ;)
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<CustomType> coGroupDs = ds.coGroup(ds2)
			.where(new KeySelector6()).equalTo(6).with(new CoGroup3());

	List<CustomType> result = coGroupDs.collect();

	String expected = 	"-1,20000,Flink\n" +
			"-1,10000,Flink\n" +
			"-1,30000,Flink\n";

	compareResultAsText(result, expected);
}
 
Example #22
Source File: CoGroupITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupFieldSelectorAndKeySelector() throws Exception {
	/*
	 * CoGroup field-selector (expression keys) + key selector function
	 * The key selector is simple here
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<CustomType> coGroupDs = ds.coGroup(ds2)
			.where(new KeySelector1()).equalTo(6).with(new CoGroup2());

	List<CustomType> result = coGroupDs.collect();

	String expected = "-1,20000,Flink\n" +
			"-1,10000,Flink\n" +
			"-1,30000,Flink\n";

	compareResultAsText(result, expected);
}
 
Example #23
Source File: CoGroupITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupFieldSelectorAndComplicatedKeySelector() throws Exception {
	/*
	 * CoGroup field-selector (expression keys) + key selector function
	 * The key selector is unnecessary complicated (Tuple1) ;)
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<CustomType> coGroupDs = ds.coGroup(ds2)
			.where(new KeySelector6()).equalTo(6).with(new CoGroup3());

	List<CustomType> result = coGroupDs.collect();

	String expected = 	"-1,20000,Flink\n" +
			"-1,10000,Flink\n" +
			"-1,30000,Flink\n";

	compareResultAsText(result, expected);
}
 
Example #24
Source File: RowTsFileOutputFormatTestBase.java    From incubator-iotdb with Apache License 2.0 6 votes vote down vote up
protected List<Row> prepareData() {
	List<Tuple7> tuples = new ArrayList<>(7);
	tuples.add(new Tuple7(1L, 1.2f, 20, null, 2.3f, 11, 19));
	tuples.add(new Tuple7(2L, null, 20, 50, 25.4f, 10, 21));
	tuples.add(new Tuple7(3L, 1.4f, 21, null, null, null, null));
	tuples.add(new Tuple7(4L, 1.2f, 20, 51, null, null, null));
	tuples.add(new Tuple7(6L, 7.2f, 10, 11, null, null, null));
	tuples.add(new Tuple7(7L, 6.2f, 20, 21, null, null, null));
	tuples.add(new Tuple7(8L, 9.2f, 30, 31, null, null, null));

	return tuples.stream().map(t -> {
		Row row = new Row(7);
		for (int i = 0; i < 7; i++) {
			row.setField(i, t.getField(i));
		}
		return row;
	}).collect(Collectors.toList());
}
 
Example #25
Source File: CoGroupITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCoGroupOnTwoCustomTypeInputsWithExpressionKeyAndFieldSelector() throws
		Exception {
	/*
	 * CoGroup on two custom type inputs using expression keys
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<CustomType> coGroupDs = ds.coGroup(ds2)
			.where("nestedPojo.longNumber").equalTo(6).with(new CoGroup1());

	List<CustomType> result = coGroupDs.collect();

	String expected = 	"-1,20000,Flink\n" +
			"-1,10000,Flink\n" +
			"-1,30000,Flink\n";

	compareResultAsText(result, expected);
}
 
Example #26
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectingMultipleFieldsUsingExpressionLanguage() throws Exception {
	/*
	 * selecting multiple fields using expression language
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedPojo.longNumber", "number", "str").equalTo("f6", "f0", "f1");

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #27
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testFullPojoWithFullTuple() throws Exception {
	/*
	 * full pojo with full tuple
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Long, Integer, Integer, Long, String, Integer, String>> ds2 = CollectionDataSets.getSmallTuplebasedDataSetMatchingPojo(env);
	DataSet<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> joinDs =
			ds1.join(ds2).where("*").equalTo("*");

	env.setParallelism(1);
	List<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String>>> result = joinDs.collect();

	String expected = "1 First (10,100,1000,One) 10000,(10000,10,100,1000,One,1,First)\n" +
			"2 Second (20,200,2000,Two) 20000,(20000,20,200,2000,Two,2,Second)\n" +
			"3 Third (30,300,3000,Three) 30000,(30000,30,300,3000,Three,3,Third)\n";

	compareResultAsTuples(result, expected);
}
 
Example #28
Source File: AdvertisingTopologyFlinkStateHighKeyCard.java    From yahoo-streaming-benchmark with Apache License 2.0 6 votes vote down vote up
@Override
public void flatMap(String input, Collector<Tuple7<String, String, String, String, String, String, String>> out)
  throws Exception {
  JSONObject obj = (JSONObject) parser.parse(input);

  Tuple7<String, String, String, String, String, String, String> tuple =
    new Tuple7<>(
      obj.getAsString("user_id"),
      obj.getAsString("page_id"),
      obj.getAsString("campaign_id"),
      obj.getAsString("ad_type"),
      obj.getAsString("event_type"),
      obj.getAsString("event_time"),
      obj.getAsString("ip_address"));
  out.collect(tuple);
}
 
Example #29
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinNestedPojoAgainstTupleSelectedUsingString() throws Exception {
	/*
	 * Join nested pojo against tuple (selected using a string)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedPojo.longNumber").equalTo("f6");

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

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}
 
Example #30
Source File: JoinITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinNestedPojoAgainstTupleSelectedUsingInteger() throws Exception {
	/*
	 * Join nested pojo against tuple (selected as an integer)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
	DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
	DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>>> joinDs =
			ds1.join(ds2).where("nestedPojo.longNumber").equalTo(6); // <--- difference!

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

	String expected = "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
			"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
			"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";

	compareResultAsTuples(result, expected);
}