本文整理了Java中org.apache.flink.api.common.accumulators.Accumulator.add()
方法的一些代码示例,展示了Accumulator.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Accumulator.add()
方法的具体详情如下:
包路径:org.apache.flink.api.common.accumulators.Accumulator
类名称:Accumulator
方法名:add
暂无
代码示例来源:origin: apache/flink
@Override
public void invoke(T value) throws Exception {
count++;
getRuntimeContext().getAccumulator(NUM_ELEMENTS_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void invoke(T value, Context context) throws Exception {
count++;
getRuntimeContext().getAccumulator(NUM_ELEMENTS_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
out.collect(value);
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
}
代码示例来源:origin: apache/flink
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
out.collect(value);
ValueState<Long> state = getRuntimeContext().getState(stateDescriptor);
if (state == null) {
throw new RuntimeException("Missing key value state for " + value);
}
assertEquals(value.f1, state.value());
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void processElement(StreamRecord<Tuple2<Long, Long>> element) throws Exception {
userFunction.flatMap(element.getValue(), new TimestampedCollector<>(output));
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
}
代码示例来源:origin: apache/flink
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
out.collect(value);
ValueState<Long> state = getRuntimeContext().getState(stateDescriptor);
if (state == null) {
throw new RuntimeException("Missing key value state for " + value);
}
assertEquals(value.f1, state.value());
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
out.collect(value);
ValueState<Long> state = getRuntimeContext().getState(stateDescriptor);
if (state == null) {
throw new RuntimeException("Missing key value state for " + value);
}
assertEquals(value.f1, state.value());
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void flatMap(Tuple2<Long, Long> value, Collector<Tuple2<Long, Long>> out) throws Exception {
out.collect(value);
ValueState<Long> state = getRuntimeContext().getState(stateDescriptor);
if (state == null) {
throw new RuntimeException("Missing key value state for " + value);
}
assertEquals(value.f1, state.value());
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void run(SourceContext<Tuple2<Long, Long>> ctx) throws Exception {
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
// immediately trigger any set timers
ctx.emitWatermark(new Watermark(1000));
synchronized (ctx.getCheckpointLock()) {
for (long i = 0; i < numElements; i++) {
ctx.collect(new Tuple2<>(i, i));
}
}
while (isRunning) {
Thread.sleep(20);
}
}
代码示例来源:origin: apache/flink
@Override
public void initializeState(FunctionInitializationContext context) throws Exception {
ListState<String> unionListState = context.getOperatorStateStore().getUnionListState(
CheckpointingNonParallelSourceWithListState.STATE_DESCRIPTOR);
if (context.isRestored()) {
assertThat(unionListState.get(),
containsInAnyOrder(CheckpointingParallelSourceWithUnionListState.CHECKPOINTED_STRINGS));
getRuntimeContext().addAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR, new IntCounter());
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
} else {
throw new RuntimeException(
"This source should always be restored because it's only used when restoring from a savepoint.");
}
}
代码示例来源:origin: apache/flink
@Override
public void initializeState(FunctionInitializationContext context) throws Exception {
ListState<String> unionListState = context.getOperatorStateStore().getListState(
CheckpointingNonParallelSourceWithListState.STATE_DESCRIPTOR);
if (context.isRestored()) {
assertThat(unionListState.get(),
containsInAnyOrder(
CheckpointingNonParallelSourceWithListState.CHECKPOINTED_STRING,
CheckpointingNonParallelSourceWithListState.CHECKPOINTED_STRING_1,
CheckpointingNonParallelSourceWithListState.CHECKPOINTED_STRING_2,
CheckpointingNonParallelSourceWithListState.CHECKPOINTED_STRING_3));
getRuntimeContext().addAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR, new IntCounter());
getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1);
} else {
throw new RuntimeException(
"This source should always be restored because it's only used when restoring from a savepoint.");
}
}
代码示例来源:origin: apache/flink
@Override
public void onEventTime(InternalTimer<Long, Long> timer) throws Exception {
ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
timer.getNamespace(),
LongSerializer.INSTANCE,
stateDescriptor);
assertEquals(state.value(), timer.getNamespace());
getRuntimeContext().getAccumulator(SUCCESSFUL_EVENT_TIME_CHECK_ACCUMULATOR).add(1);
}
代码示例来源:origin: apache/flink
@Override
public void onEventTime(InternalTimer<Long, Long> timer) throws Exception {
ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
timer.getNamespace(),
LongSerializer.INSTANCE,
stateDescriptor);
assertEquals(state.value(), timer.getNamespace());
getRuntimeContext().getAccumulator(SUCCESSFUL_EVENT_TIME_CHECK_ACCUMULATOR).add(1);
}
代码示例来源:origin: apache/flink
@Override
public void onProcessingTime(InternalTimer<Long, Long> timer) throws Exception {
ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
timer.getNamespace(),
LongSerializer.INSTANCE,
stateDescriptor);
assertEquals(state.value(), timer.getNamespace());
getRuntimeContext().getAccumulator(SUCCESSFUL_PROCESSING_TIME_CHECK_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void onProcessingTime(InternalTimer<Long, Long> timer) throws Exception {
ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
timer.getNamespace(),
LongSerializer.INSTANCE,
stateDescriptor);
assertEquals(state.value(), timer.getNamespace());
getRuntimeContext().getAccumulator(SUCCESSFUL_PROCESSING_TIME_CHECK_ACCUMULATOR).add(1);
}
}
代码示例来源:origin: apache/flink
@Override
public void processElement(StreamRecord<Tuple2<Long, Long>> element) throws Exception {
ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
element.getValue().f0,
LongSerializer.INSTANCE,
stateDescriptor);
assertEquals(state.value(), element.getValue().f1);
getRuntimeContext().getAccumulator(SUCCESSFUL_PROCESS_CHECK_ACCUMULATOR).add(1);
output.collect(element);
}
代码示例来源:origin: apache/flink
@Override
public void processElement(StreamRecord<Tuple2<Long, Long>> element) throws Exception {
ValueState<Long> state = getKeyedStateBackend().getPartitionedState(
element.getValue().f0,
LongSerializer.INSTANCE,
stateDescriptor);
assertEquals(state.value(), element.getValue().f1);
getRuntimeContext().getAccumulator(SUCCESSFUL_PROCESS_CHECK_ACCUMULATOR).add(1);
output.collect(element);
}
代码示例来源:origin: com.alibaba.blink/flink-examples-streaming
@Override
public void flatMap1(Customer customer, Collector<ShippingPriorityItem> collector) throws Exception {
if (objectReuse) {
//noinspection BoxingBoxedValue
customKeys.add(new Long(customer.getCustKey()));
} else {
customKeys.add(customer.getCustKey());
}
customBeforeJoin.add(1L);
}
代码示例来源:origin: com.alibaba.blink/flink-examples-streaming
@Override
public void flatMap1(ShippingPriorityItem priorityItem, Collector<ShippingPriorityItem> out) throws Exception {
if (objectReuse) {
orders.put(priorityItem.getOrderkey(), new ShippingPriorityItem(priorityItem));
} else {
orders.put(priorityItem.getOrderkey(), priorityItem);
}
customJoinedOrderWithoutLineitem.add(1L);
}
代码示例来源:origin: com.alibaba.blink/flink-examples-streaming
@Override
public void flatMap2(Lineitem lineitem, Collector<ShippingPriorityItem> collector) throws Exception {
final ShippingPriorityItem priorityItem = orders.get(lineitem.getOrderkey());
if (priorityItem != null) {
long start = System.currentTimeMillis();
if (objectReuse) {
collector.collect(
new ShippingPriorityItem(
priorityItem.f0,
lineitem.getExtendedprice() * (1 - lineitem.getDiscount()),
priorityItem.f2,
priorityItem.f3));
} else {
priorityItem.setRevenue(lineitem.getExtendedprice() * (1 - lineitem.getDiscount()));
collector.collect(priorityItem);
}
broadcastCost.add(System.currentTimeMillis() - start);
lineitemJoinedOthers.add(1L);
}
lineitemBeforeJoin.add(1L);
}
}
内容来源于网络,如有侵权,请联系作者删除!