【问题标题】:How to map tuples with persistent state in Trident?如何在 Trident 中映射具有持久状态的元组?
【发布时间】:2013-11-08 12:51:52
【问题描述】:

我正在学习Trident 框架。在 Trident Streams 上有几种方法用于批处理中的聚合元组,包括 this one,它允许使用 Aggregator 接口对元组进行状态映射。但不幸的是,不存在用于额外持久化地图状态的内置对应项,例如 persistentAggregate() 的其他 9 个重载,仅以 Aggregator 作为参数。

因此,如何通过结合较低级别的 Trident 和 Storm 抽象和工具来实现所需的功能?探索 API 非常困难,因为几乎没有 Javadoc 文档。

换句话说,persistentAggregate() 方法允许通过更新一些持久状态来结束流处理:

stream of tuples ---> persistent state

我想更新持久化状态,顺便发出不同的元组:

stream of tuples ------> stream of different tuples
                  with
            persistent state

Stream.aggregate(Fields, Aggregator, Fields) 不提供容错:

stream of tuples ------> stream of different tuples
                  with
          simple in-memory state

【问题讨论】:

  • 你能不能说得详细点。你的问题不清楚
  • @GlobalWarrior 查看问题更新
  • 你不能用同一套元组发布两个单独的流吗?其中一个保持状态,而其他人则执行您想要的修改。
  • @GlobalWarrior 映射是有状态的。要发出一个新元组,我需要知道当前状态。

标签: stream state apache-storm trident


【解决方案1】:

您可以使用TridentState#newValuesStream() 方法从状态创建新流。 这将允许您检索聚合值的流。

出于说明目的,我们可以通过添加此方法和调试过滤器来改进example in Trident documentation

FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3,
    new Values("the cow jumped over the moon"),
    new Values("the man went to the store and bought some candy"),
    new Values("four score and seven years ago"),
    new Values("how many apples can you eat"));
spout.setCycle(true);

TridentTopology topology = new TridentTopology();        
topology.newStream("spout1", spout)
    .each(new Fields("sentence"), new Split(), new Fields("word"))
    .groupBy(new Fields("word"))
    .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))                
    .newValuesStream().each(new Fields("count"), new Debug());

运行此拓扑将输出(到控制台)聚合计数。

希望对你有帮助

【讨论】:

  • 我不需要聚合计数流。我想有状态地转换值流。 This 方法解决了这个问题,除了 Aggregator 类不支持持久性。
  • 如果我理解,您想根据先前的状态转换元组,然后更新状态并发出转换后的元组。你能确认一下吗?
  • 根据当前状态。简单地说,我对Aggregator 的持续实现感到满意,但由于它不存在(至少在标准的 Storm 发行版中),我正在寻找不同的方法。
  • 你试过stateQuery()吗?
猜你喜欢
  • 2012-06-16
  • 1970-01-01
  • 2020-01-15
  • 1970-01-01
  • 2021-01-30
  • 2018-09-01
  • 2019-10-27
  • 2017-05-07
  • 1970-01-01
相关资源
最近更新 更多