当前的Hazelcast Jet 0.6.1代码示例演示了基于单个字段的聚合(例如,自动收报机)。
这是一个参考。
\ code-samples \ streaming \ stock-exchange \ src \ main \ java \ StockExchange.java
如何将其扩展为多个,如ticker,traderId等。
以下是StockExchange.java
private static Pipeline buildPipeline() {
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<Trade, Integer, Trade>mapJournal(TRADES_MAP_NAME,
alwaysTrue(), EventJournalMapEvent::getNewValue, START_FROM_CURRENT))
.addTimestamps(Trade::getTime, 3000)
.groupingKey(Trade::getTicker)
.window(WindowDefinition.sliding(SLIDING_WINDOW_LENGTH_MILLIS, SLIDE_STEP_MILLIS))
.aggregate(counting(),
(winStart, winEnd, key, result) -> String.format("%s %5s %4d", toLocalTime(winEnd), key, result))
.drainTo(Sinks.logger());
return p;
}
答案 0 :(得分:1)
对于自动收报机和traderId你可以使用:
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="collapse navbar-collapse justify-content-center d-flex">
<a class="navbar-brand">WIDE-LOGO-TEXT</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link">Home</a>
</li>
<li class="nav-item">
<a class="nav-link">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link">Services</a>
</li>
<li class="nav-item">
<a class="nav-link">Contact Us</a>
</li>
</ul>
</div>
</nav>
<!-- Second NavBar: -->
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="collapse navbar-collapse d-flex">
<a class="navbar-brand">WIDE-LOGO-TEXT</a>
<ul class="navbar-nav" style="margin: 0 auto;">
<li class="nav-item">
<a class="nav-link">Home</a>
</li>
<li class="nav-item">
<a class="nav-link">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link">Services</a>
</li>
<li class="nav-item">
<a class="nav-link">Contact Us</a>
</li>
</ul>
</div>
</nav>
通常,密钥可以通过正确实现.groupingKey(trade -> Tuple2.tuple2(trade.getTicker(), trade.getTraderId()))
和equals
的任何内容来实现。 hashCode
是两个值的通用容器。
答案 1 :(得分:0)
我们还可以为分组提供逗号分隔的键。
.aggregate(AggregateOperations.groupingBy(data -> {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(StringUtils.defaultString(data.getSource1().get(dataValue) + "", "")).append(",");
return stringBuilder.substring(0, stringBuilder.toString().length() - 1);
}));