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

The following examples show how to use org.apache.flink.api.java.DataSet#distinct() . 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: DistinctITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectnessOfDistinctOnAtomic() throws Exception {
	/*
	 * check correctness of distinct on Integers
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Integer> ds = CollectionDataSets.getIntegerDataSet(env);
	DataSet<Integer> reduceDs = ds.distinct();

	List<Integer> result = reduceDs.collect();

	String expected = "1\n2\n3\n4\n5";

	compareResultAsText(result, expected);
}
 
Example 2
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("serial")
public void testDistinctByKeySelector1() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	this.customTypeData.add(new CustomType());

	try {
		DataSet<CustomType> customDs = env.fromCollection(customTypeData);
		// should work
		customDs.distinct(
				new KeySelector<DistinctOperatorTest.CustomType, Long>() {

					@Override
					public Long getKey(CustomType value) {
						return value.myLong;
				}
		});
	} catch (Exception e) {
		Assert.fail();
	}

}
 
Example 3
Source File: DistinctOperatorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("serial")
public void testDistinctByKeySelector1() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	this.customTypeData.add(new CustomType());

	try {
		DataSet<CustomType> customDs = env.fromCollection(customTypeData);
		// should work
		customDs.distinct(
				new KeySelector<DistinctOperatorTest.CustomType, Long>() {

					@Override
					public Long getKey(CustomType value) {
						return value.myLong;
				}
		});
	} catch (Exception e) {
		Assert.fail();
	}

}
 
Example 4
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("serial")
public void testDistinctByKeySelector1() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	this.customTypeData.add(new CustomType());

	try {
		DataSet<CustomType> customDs = env.fromCollection(customTypeData);
		// should work
		customDs.distinct(
				new KeySelector<DistinctOperatorTest.CustomType, Long>() {

					@Override
					public Long getKey(CustomType value) {
						return value.myLong;
				}
		});
	} catch (Exception e) {
		Assert.fail();
	}

}
 
Example 5
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDistinctByKeyFields7(){
	final ExecutionEnvironment env  = ExecutionEnvironment.getExecutionEnvironment();
	DataSet<Long> longDs = env.fromCollection(emptyLongData, BasicTypeInfo.LONG_TYPE_INFO);

	// should work
	try {
		longDs.distinct("*");
	} catch (Exception e){
		Assert.fail();
	}
}
 
Example 6
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctOnNotKeyDataType() throws Exception {
   	/*
    	* should not work. NotComparable data type cannot be used as key
    	*/
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	NotComparable a = new NotComparable();
	List<NotComparable> l = new ArrayList<NotComparable>();
	l.add(a);

	DataSet<NotComparable> ds = env.fromCollection(l);
	DataSet<NotComparable> reduceDs = ds.distinct();

}
 
Example 7
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctOnNotKeyDataType() throws Exception {
   	/*
    	* should not work. NotComparable data type cannot be used as key
    	*/
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	NotComparable a = new NotComparable();
	List<NotComparable> l = new ArrayList<NotComparable>();
	l.add(a);

	DataSet<NotComparable> ds = env.fromCollection(l);
	DataSet<NotComparable> reduceDs = ds.distinct();

}
 
Example 8
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDistinctByKeyFields4() {

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

	// should work
	tupleDs.distinct();
}
 
Example 9
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctByKeyFields2() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Long> longDs = env.fromCollection(emptyLongData, BasicTypeInfo.LONG_TYPE_INFO);
	// should not work: distinct on basic type
	longDs.distinct(0);
}
 
Example 10
Source File: DistinctOperatorTest.java    From flink with 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 11
Source File: DistinctOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctOnNotKeyDataTypeOnSelectAllChar() throws Exception {
   	/*
    	* should not work. NotComparable data type cannot be used as key
    	*/
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	NotComparable a = new NotComparable();
	List<NotComparable> l = new ArrayList<NotComparable>();
	l.add(a);

	DataSet<NotComparable> ds = env.fromCollection(l);
	DataSet<NotComparable> reduceDs = ds.distinct("*");
}
 
Example 12
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctByKeyFields2() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Long> longDs = env.fromCollection(emptyLongData, BasicTypeInfo.LONG_TYPE_INFO);
	// should not work: distinct on basic type
	longDs.distinct(0);
}
 
Example 13
Source File: DistinctOperatorTest.java    From flink with 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 14
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void  testDistinctByKeyIndices1() {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	try {
		DataSet<Long> longDs = env.fromCollection(emptyLongData, BasicTypeInfo.LONG_TYPE_INFO);
		// should work
		longDs.distinct();
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example 15
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDistinctByKeyFields4() {

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

	// should work
	tupleDs.distinct();
}
 
Example 16
Source File: DistinctOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctByKeyFields2() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Long> longDs = env.fromCollection(emptyLongData, BasicTypeInfo.LONG_TYPE_INFO);
	// should not work: distinct on basic type
	longDs.distinct(0);
}
 
Example 17
Source File: DistinctOperatorTest.java    From Flink-CEPplus with 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 18
Source File: DistinctOperatorTest.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
@Test
public void testDistinctByKeyFields5() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	this.customTypeData.add(new CustomType());

	DataSet<CustomType> customDs = env.fromCollection(customTypeData);

	// should work
	customDs.distinct();
}
 
Example 19
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 3 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctByKeyFields3() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	this.customTypeData.add(new CustomType());

	DataSet<CustomType> customDs = env.fromCollection(customTypeData);
	// should not work: distinct on custom type
	customDs.distinct(0);

}
 
Example 20
Source File: DistinctOperatorTest.java    From flink with Apache License 2.0 3 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testDistinctByKeyFields3() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	this.customTypeData.add(new CustomType());

	DataSet<CustomType> customDs = env.fromCollection(customTypeData);
	// should not work: distinct on custom type
	customDs.distinct(0);

}