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

The following examples show how to use org.apache.flink.api.java.DataSet#maxBy() . 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: MaxByOperatorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * This test validates that no exceptions is thrown when an empty dataset
 * calls maxBy().
 */
@Test
public void testMaxByKeyFieldsDataset() {

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

	// should work
	try {
		tupleDs.maxBy(4, 0, 1, 2, 3);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example 2
Source File: MaxByOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This test validates that no exceptions is thrown when an empty dataset
 * calls maxBy().
 */
@Test
public void testMaxByKeyFieldsDataset() {

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

	// should work
	try {
		tupleDs.maxBy(4, 0, 1, 2, 3);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example 3
Source File: MaxByOperatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This test validates that no exceptions is thrown when an empty dataset
 * calls maxBy().
 */
@Test
public void testMaxByKeyFieldsDataset() {

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

	// should work
	try {
		tupleDs.maxBy(4, 0, 1, 2, 3);
	} catch (Exception e) {
		Assert.fail();
	}
}
 
Example 4
Source File: MaxByOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * This test validates that an InvalidProgramException is thrown when maxBy
 * is used on a custom data type.
 */
@Test(expected = InvalidProgramException.class)
public void testCustomKeyFieldsDataset() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

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

	DataSet<CustomType> customDs = env.fromCollection(customTypeData);
	// should not work: groups on custom type
	customDs.maxBy(0);
}
 
Example 5
Source File: MaxByOperatorTest.java    From Flink-CEPplus with 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.maxBy(5);
}
 
Example 6
Source File: MaxByOperatorTest.java    From Flink-CEPplus with 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 testOutOfTupleBoundsDataset2() {

	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);
}
 
Example 7
Source File: MaxByOperatorTest.java    From Flink-CEPplus with 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 8
Source File: MaxByOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test validates that an InvalidProgramException is thrown when maxBy
 * is used on a custom data type.
 */
@Test(expected = InvalidProgramException.class)
public void testCustomKeyFieldsDataset() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

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

	DataSet<CustomType> customDs = env.fromCollection(customTypeData);
	// should not work: groups on custom type
	customDs.maxBy(0);
}
 
Example 9
Source File: MaxByOperatorTest.java    From flink with 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.maxBy(5);
}
 
Example 10
Source File: MaxByOperatorTest.java    From flink with 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 testOutOfTupleBoundsDataset2() {

	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);
}
 
Example 11
Source File: MaxByOperatorTest.java    From flink with 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 12
Source File: MaxByOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test validates that an InvalidProgramException is thrown when maxBy
 * is used on a custom data type.
 */
@Test(expected = InvalidProgramException.class)
public void testCustomKeyFieldsDataset() {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

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

	DataSet<CustomType> customDs = env.fromCollection(customTypeData);
	// should not work: groups on custom type
	customDs.maxBy(0);
}
 
Example 13
Source File: MaxByOperatorTest.java    From flink with 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.maxBy(5);
}
 
Example 14
Source File: MaxByOperatorTest.java    From flink with 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 testOutOfTupleBoundsDataset2() {

	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);
}
 
Example 15
Source File: MaxByOperatorTest.java    From flink with 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 16
Source File: MaxByOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that no ClassCastException happens
 * should not fail e.g. like in FLINK-8255.
 */
@Test(expected = InvalidProgramException.class)
public void testMaxByRowTypeInfoKeyFieldsDataset() {

	final ExecutionEnvironment env = ExecutionEnvironment
			.getExecutionEnvironment();
	TypeInformation[] types = new TypeInformation[] {Types.INT, Types.INT};

	String[] fieldNames = new String[]{"id", "value"};
	RowTypeInfo rowTypeInfo = new RowTypeInfo(types, fieldNames);
	DataSet tupleDs = env
			.fromCollection(Collections.singleton(new Row(2)), rowTypeInfo);

	tupleDs.maxBy(0);
}