简体   繁体   English

点燃缓存值的总和

[英]Ignite Cache Sum of values

I am using Ignite tutorial code (link below), but I want to modify it such that it operates on a different type of data and the counts are done differently - rather than incrementing counter by 1 I want to add a current value. 我正在使用Ignite教程代码(下面的链接),但是我想对其进行修改,使其对不同类型的数据进行操作,并且计数方式有所不同-而不是将计数器加1,我想添加一个当前值。

So let's assume I have number of occurences of a certain word in different documents, so let's assume I have something like this: 因此,假设我在不同文档中出现某个单词的次数很多,因此假设我有这样的事情:

'the' 6586 6586

'the' 925 925

So I want Cache to hold 'the' 7511 所以我想让Cache保持7511

So given this: 因此,鉴于此:

try (Stream<String> lines = Files.lines(path)) {
            lines.forEach(line -> {
              Stream<String> words = Stream.of(line.split(" "));
              List<String> tokens = words.collect(Collectors.toList());
              // this is just to emphasize that I want to pass value
              Long value = Long.parseLong(tokens.get(1));
              stmr.addData(tokens.get(0), Long.parseLong(tokens.get(1));

I would like the value to be passed to the stmr.receiver() method, so I can add it to the val . 我希望将传递给stmr.receiver()方法,因此可以将其添加到val中

I have even tried creating a class variable in StreamWords that would store the value, but the value does not get updated, and in stmr.receiver() it is still 0 ( as initialized). 我什至尝试在StreamWords中创建一个类变量来存储该值,但该值不会更新,并且在stmr.receiver()中仍为0(已初始化)。

Link to tutorial: Word Count Ignite Example 链接到教程: 字数统计示例

I managed to figure it out. 我设法弄清楚了。 In stmr.receiver(), arg is actually the value that I would like to insert, so just cast it to the object of your desire and you should be able to get the value. 在stmr.receiver()中,arg实际上是我要插入的值,因此只需将其强制转换为您想要的对象,您就可以获取该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM