【发布时间】:2017-04-22 10:39:57
【问题描述】:
私有数据流 buySideVolumeWMA(DataStream buyPressureTradeStream) {
Integer windowSize = 3;
Integer windowslide = 1;
DataStream<Double> buySideVolumeWMAStream = buyPressureTradeStream.countWindowAll(windowSize, windowslide)
.apply(new AllWindowFunction<String, Double, GlobalWindow>() {
@Override
public void apply(GlobalWindow window, Iterable<String> values, Collector<Double> out)
throws Exception {
Double buySideVolumeWMA = 0.0;
Integer weight = windowSize;
Integer numerator = 1;
for (String tradeString : values) {
JSONObject json = new JSONObject(tradeString);
Double tradeVolume = (Double) json.get("Volume");
buySideVolumeWMA += ((tradeVolume * numerator) / weight);
slf4jLogger.info("tradeVolume " + tradeVolume + " , " + "numerator , " + numerator
+ " weight , " + weight + " buySideVolumeWMA " + buySideVolumeWMA);
numerator++;
}
numerator = 1;
out.collect(buySideVolumeWMA / 2);
buySideVolumePressure = buySideVolumeWMA / 2;
// slf4jLogger.info("buySideVolumePressure :" +
// buySideVolumePressure);
buySideVolumeWMAStream.print().setParallelism(5);
return buySideVolumeWMAStream;
}
================================================ ========================= 在这个程序中,我使用的窗口大小为 3,幻灯片大小为 1。我希望它在收到后开始滑动计数为 3 的流数据,然后仅开始滑动 1。但是发生的情况是,我的程序在接收到第一个数据时立即开始滑动,然后它接收到的每一个数据都滑动。那么如何让它只有在收到后才滑动计数 3 的数据然后滑动 1?
【问题讨论】:
-
您的问题不清楚。您能否详细说明您的问题是什么。你应该添加一个你得到什么和想要什么的例子。
-
@ImbaBalboa 。感谢您的回复。我在程序下方添加了有关我的问题的更多详细信息。您能指导我吗?谢谢
标签: apache-flink flink-streaming