以下代码演示function, filter, projection的使用,可结合注释

省略部分代码,省略部分可参考:https://blog.csdn.net/nickta/article/details/79666918

FixedBatchSpout spout = new FixedBatchSpout(new Fields("user", "score"), 3,  new Values("nickt1", 4), new Values("nickt2", 7),  new Values("nickt3", 8), new Values("nickt4", 9),  new Values("nickt5", 7), new Values("nickt6", 11), new Values("nickt7", 5) ); spout.setCycle(false); TridentTopology topology = new TridentTopology(); topology.newStream("spout1", spout) .shuffle() .each(new Fields("user"),new BaseFilter() {@Overridepublic boolean isKeep(TridentTuple tuple) {if(tuple.getString(0).equals("nickt2")) {return false;}return true;}})//过滤点user为nickt2的tuple.each(new Fields("user", "score"),new Debug("filter print:")).each(new Fields("score"), new BaseFunction() {@Overridepublic void execute(TridentTuple tuple, TridentCollector collector) {collector.emit(new Values(tuple.getIntegerByField("score") + 100));}}, new Fields("sum"))//把score加上100后,生成新的sum字段,并追加到原字段后面,此步操作后就包括了user/score/sum三个字段.each(new Fields("user", "score", "sum"),new Debug("function print:")).project(new Fields("user")).each(new Fields("user"),new Debug("project print:"));//project投射之后,只有user字段了

输出:

<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(filter print:): [nickt1, 4]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(function print:): [nickt1, 4, 104]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(project print:): [nickt1]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(filter print:): [nickt3, 8]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(function print:): [nickt3, 8, 108]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(project print:): [nickt3]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(filter print:): [nickt4, 9]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(function print:): [nickt4, 9, 109]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(project print:): [nickt4]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(filter print:): [nickt5, 7]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(function print:): [nickt5, 7, 107]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(project print:): [nickt5]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(filter print:): [nickt6, 11]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(function print:): [nickt6, 11, 111]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(project print:): [nickt6]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(filter print:): [nickt7, 5]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(function print:): [nickt7, 5, 105]
<Sat Mar 24 13:41:42 CST 2018[partition0-Thread-68-b-0-executor[33 33]]> DEBUG(project print:): [nickt7]

转载于:https://www.cnblogs.com/nickt/p/8638663.html

Storm Trident示例function, filter, projection相关推荐

  1. Storm Trident示例shuffleparallelismHint

    本例包括Storm Trident中shuffle与parallelismHint的使用. 代码当中包括注释 maven <dependency><groupId>org.ap ...

  2. Storm Trident API

    在Storm Trident中有五种操作类型 Apply Locally:本地操作,所有操作应用在本地节点数据上,不会产生网络传输 Repartitioning:数据流重定向,单纯的改变数据流向,不会 ...

  3. [Trident] Storm Trident 教程,state详解、trident api详解及实例

    英文原址:https://github.com/nathanmarz/storm/wiki/Trident-tutorial ---------------- Trident是在storm基础上,一个 ...

  4. Storm Trident 详细介绍

    一.概要 1.1 Storm(简介)      Storm是一个实时的可靠地分布式流计算框架.      具体就不多说了,举个例子,它的一个典型的大数据实时计算应用场景:从Kafka消息队列读取消息( ...

  5. Storm Trident拓扑中的错误处理

    这篇文章总结了我在设计Storm Trident拓扑时当前的错误处理方法. 我在这里关注代码设计,而不是监督或冗余之类的部署良好实践. 由于Storm的实时流性质,当面对大多数错误时,我们最终将不得不 ...

  6. Storm Trident简介

    转载自:[翻译][Trident] Storm Trident 教程 英文原址:https://github.com/nathanmarz/storm/wiki/Trident-tutorial -- ...

  7. storm trident mysql_Trident-MySQL

    使用事物TridentTopology 持久化数据到MySQL1.构建拓扑JDBCTopology类packagestorm.trident.mysql;importjava.util.Arrays; ...

  8. Storm - Trident

    [align=center][size=large]Trident[/size][/align] 一.Storm 保证性 1.数据一定会发送 通过 ack / fail 方法确认,若失败,则提供重新发 ...

  9. Storm Trident API实践

    译 在4月10日柏林BigData啤酒节上,Pere介绍了Trident,于此同时,来自Continuum Analytics也介绍了Disco.在Storm环节中大家了解了正确使用Trident的基 ...

最新文章

  1. 三星S4接电话黑屏无法挂断通话
  2. c拆分字符串,并按照指定格式存入结构体数组
  3. SSH 连接慢 与 反向解析
  4. collections模块介绍
  5. 【大数据教程】HDFS基本架构、基本命令、回收站机制和API操作
  6. py_文件操作_01
  7. burp suite 二级域名扫描插件
  8. js获取字符串最后一个字符代码
  9. [学习笔记]后缀平衡树
  10. 程序员刚入职很痛苦_在中国,程序员这行能干一辈子吗?
  11. Python入门-函数
  12. 《教孩子学编程(Python语言版)》——1.3 运行Python程序
  13. linux的守护进程init.d和xinetd.d
  14. lsd 特征点匹配代码_直线匹配-LSD算法
  15. 从行业共生到产业共生——2021 MWC上海展观察
  16. 魅族 系统更新服务器,Flyme
  17. 从.Net类库代码来看Asp.net运行时(转自酷网动力)
  18. 公司新来了个00后测试工程师,一副毛头小子的样儿,哪想到是新一代卷王...
  19. BeyondCompare| Beyond Compare永久适用
  20. 奶块服务器维护多久,奶块为什么要更新维护 | 手游网游页游攻略大全

热门文章

  1. postgresql开发中可能有用的知识
  2. jquery treeview 树形插件
  3. 自动填充脚本使用及注意事项
  4. anki_Anki如何挽救我的工程生涯
  5. 安卓开发|自定义监听器的三个步骤
  6. hung-yi lee_p11_逻辑回归
  7. Hibernate和iBATIS 优缺点比较
  8. [设计模式]外观模式
  9. 公有云环境下应用程序的自动化部署与水平扩展问题
  10. 对象Equals相等性比较的通用实现