本文整理汇总了Java中org.apache.flink.api.common.operators.util.UserCodeWrapper.getUserCodeObject方法的典型用法代码示例。如果您正苦于以下问题:Java UserCodeWrapper.getUserCodeObject方法的具体用法?Java UserCodeWrapper.getUserCodeObject怎么用?Java UserCodeWrapper.getUserCodeObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.common.operators.util.UserCodeWrapper
的用法示例。
在下文中一共展示了UserCodeWrapper.getUserCodeObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeOnMaster
import org.apache.flink.api.common.operators.util.UserCodeWrapper; //导入方法依赖的package包/类
@Override
public void initializeOnMaster(ClassLoader loader) throws Exception {
if (this.outputFormat == null) {
TaskConfig cfg = new TaskConfig(getConfiguration());
UserCodeWrapper<OutputFormat<?>> wrapper = cfg.<OutputFormat<?>>getStubWrapper(loader);
if (wrapper == null) {
throw new Exception("No output format present in OutputFormatVertex's task configuration.");
}
this.outputFormat = wrapper.getUserCodeObject(OutputFormat.class, loader);
this.outputFormat.configure(cfg.getStubParameters());
}
if (this.outputFormat instanceof InitializeOnMaster) {
((InitializeOnMaster) this.outputFormat).initializeGlobal(getParallelism());
}
}
示例2: initializeOnMaster
import org.apache.flink.api.common.operators.util.UserCodeWrapper; //导入方法依赖的package包/类
@Override
public void initializeOnMaster(ClassLoader loader) throws Exception {
if (inputFormat == null) {
TaskConfig cfg = new TaskConfig(getConfiguration());
UserCodeWrapper<InputFormat<?, ?>> wrapper = cfg.<InputFormat<?, ?>>getStubWrapper(loader);
if (wrapper == null) {
throw new Exception("No input format present in InputFormatVertex's task configuration.");
}
inputFormat = wrapper.getUserCodeObject(InputFormat.class, loader);
inputFormat.configure(cfg.getStubParameters());
}
setInputSplitSource(inputFormat);
}
示例3: testWrappedCoGroupClass
import org.apache.flink.api.common.operators.util.UserCodeWrapper; //导入方法依赖的package包/类
@Test
public void testWrappedCoGroupClass() {
try {
CoGroupOperator coGroupOp = CoGroupOperator.builder(TestCoGroupFunction.class, LongValue.class, 1, 2).build();
UserCodeWrapper<org.apache.flink.api.common.functions.CoGroupFunction<Record, Record, Record>> udf = coGroupOp.getUserCodeWrapper();
UserCodeWrapper<org.apache.flink.api.common.functions.CoGroupFunction<Record, Record, Record>> copy = SerializationUtils.clone(udf);
org.apache.flink.api.common.functions.CoGroupFunction<Record, Record, Record> cogrouper = copy.getUserCodeObject();
// prepare the coGpuü
final List<Record> target = new ArrayList<Record>();
Collector<Record> collector = new Collector<Record>() {
@Override
public void collect(Record record) {
target.add(record);
}
@Override
public void close() {}
};
List<Record> source1 = new ArrayList<Record>();
source1.add(new Record(new IntValue(42)));
source1.add(new Record(new IntValue(13)));
List<Record> source2 = new ArrayList<Record>();
source2.add(new Record(new LongValue(11)));
source2.add(new Record(new LongValue(17)));
// test coGroup
cogrouper.coGroup(source1, source2, collector);
assertEquals(4, target.size());
assertEquals(new IntValue(42), target.get(0).getField(0, IntValue.class));
assertEquals(new IntValue(13), target.get(1).getField(0, IntValue.class));
assertEquals(new LongValue(11), target.get(2).getField(0, LongValue.class));
assertEquals(new LongValue(17), target.get(3).getField(0, LongValue.class));
target.clear();
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例4: testWrappedReduceClass
import org.apache.flink.api.common.operators.util.UserCodeWrapper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testWrappedReduceClass() {
try {
ReduceOperator reduceOp = ReduceOperator.builder(TestReduceFunction.class).build();
UserCodeWrapper<GroupReduceFunction<Record, Record>> udf = reduceOp.getUserCodeWrapper();
UserCodeWrapper<GroupReduceFunction<Record, Record>> copy = SerializationUtils.clone(udf);
GroupReduceFunction<Record, Record> reducer = copy.getUserCodeObject();
// prepare the reduce / combine tests
final List<Record> target = new ArrayList<Record>();
Collector<Record> collector = new Collector<Record>() {
@Override
public void collect(Record record) {
target.add(record);
}
@Override
public void close() {}
};
List<Record> source = new ArrayList<Record>();
source.add(new Record(new IntValue(42), new LongValue(11)));
source.add(new Record(new IntValue(13), new LongValue(17)));
// test reduce
reducer.reduce(source, collector);
assertEquals(2, target.size());
assertEquals(new IntValue(42), target.get(0).getField(0, IntValue.class));
assertEquals(new LongValue(11), target.get(0).getField(1, LongValue.class));
assertEquals(new IntValue(13), target.get(1).getField(0, IntValue.class));
assertEquals(new LongValue(17), target.get(1).getField(1, LongValue.class));
target.clear();
// test combine
((FlatCombineFunction<Record>) reducer).combine(source, collector);
assertEquals(2, target.size());
assertEquals(new IntValue(42), target.get(0).getField(0, IntValue.class));
assertEquals(new LongValue(11), target.get(0).getField(1, LongValue.class));
assertEquals(new IntValue(13), target.get(1).getField(0, IntValue.class));
assertEquals(new LongValue(17), target.get(1).getField(1, LongValue.class));
target.clear();
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}