本文整理了Java中org.apache.flink.api.java.operators.UnsortedGrouping.minBy()
方法的一些代码示例,展示了UnsortedGrouping.minBy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UnsortedGrouping.minBy()
方法的具体详情如下:
包路径:org.apache.flink.api.java.operators.UnsortedGrouping
类名称:UnsortedGrouping
方法名:minBy
[英]Applies a special case of a reduce transformation (minBy) on a grouped DataSet.
The transformation consecutively calls a ReduceFunctionuntil only a single element remains which is the result of the transformation. A ReduceFunction combines two elements into one new element of the same type.
[中]对分组数据集应用reduce转换(minBy)的特殊情况。
转换连续调用reduceFunction,直到只剩下一个元素,这是转换的结果。ReduceFunction将两个元素组合成一个相同类型的新元素。
代码示例来源:origin: apache/flink
/**
* This test validates that an InvalidProgramException is thrown when minBy
* is used on a custom data type.
*/
@Test(expected = InvalidProgramException.class)
public void testCustomKeyFieldsGrouping() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
this.customTypeData.add(new CustomType());
UnsortedGrouping<CustomType> groupDs = env.fromCollection(customTypeData).groupBy(0);
// should not work: groups on custom type
groupDs.minBy(0);
}
代码示例来源:origin: apache/flink
/**
* This test validates that an index which is out of bounds throws an
* IndexOutOfBoundsException.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testOutOfTupleBoundsGrouping1() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0);
// should not work, key out of tuple bounds
groupDs.minBy(5);
}
代码示例来源:origin: apache/flink
/**
* This test validates that an index which is out of bounds throws an
* IndexOutOfBoundsException.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testOutOfTupleBoundsGrouping2() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0);
// should not work, key out of tuple bounds
groupDs.minBy(-1);
}
代码示例来源:origin: apache/flink
/**
* This test validates that an index which is out of bounds throws an
* IndexOutOfBoundsException.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testOutOfTupleBoundsGrouping3() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0);
// should not work, key out of tuple bounds
groupDs.minBy(1, 2, 3, 4, -1);
}
代码示例来源:origin: apache/flink
/**
* This test validates that no exceptions is thrown when an empty grouping
* calls minBy().
*/
@Test
public void testMinByKeyFieldsGrouping() {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
UnsortedGrouping<Tuple5<Integer, Long, String, Long, Integer>> groupDs = env.fromCollection(emptyTupleData, tupleTypeInfo).groupBy(0);
// should work
try {
groupDs.minBy(4, 0, 1, 2, 3);
} catch (Exception e) {
Assert.fail();
}
}
代码示例来源:origin: apache/flink
private static DataSet<String> analyze(DataSet<String> input, DataSet<String> stats, int branches) {
for (int i = 0; i < branches; i++) {
final int ii = i;
if (stats != null) {
input = input.map(
new RichMapFunction<String, String>() {
@Override
public String map(String value) {
return value;
}
}).withBroadcastSet(stats.map(s -> "(" + s + ").map"), "stats");
}
DataSet<String> branch = input
.map(s -> new Tuple2<>(0, s + ii)).returns(Types.TUPLE(Types.STRING, Types.INT))
.groupBy(0)
.minBy(1)
.map(kv -> kv.f1).returns(Types.STRING);
if (stats == null) {
stats = branch;
} else {
stats = stats.union(branch);
}
}
return stats.map(s -> "(" + s + ").stats");
}
}
内容来源于网络,如有侵权,请联系作者删除!