what is use of Tuple.getStringByField(“ABC”) in Storm

孤街醉人 提交于 2019-12-12 06:03:30

问题


I am not able to understand the use of the Tuple.getStringByField("ABC") in Apache Storm.

The following is the code:

   Public Void execute(Tuple input){ 
       try{
          if (input.getSourceStreamId.equals("signals"))
            {
                str=input.getStringByField("action")

                if ("refresh".equals(str))
                  {....}
             }
             }...

Here what is input.getStringByField("action") is doing exactly..

Thank you.


回答1:


In storm, both spout and bolt emit tuple. But the question is what are contained in each tuple. Each spout and bolt can use the below method to define the tuple schema.

  @Override
  public void declareOutputFields(
      OutputFieldsDeclarer outputFieldsDeclarer)
  {
    // tell storm the schema of the output tuple
    // tuple consists of columns called 'mycolumn1' and 'mycolumn2'
    outputFieldsDeclarer.declare(new Fields("mycolumn1", "mycolumn2"));
  }

The subsequent bolt then can use getStringByField("mycolumn1") to retrieve the value based on column name.




回答2:


getStringByField() is like getString(), except it looks up the field by it's field name instead of position.



来源:https://stackoverflow.com/questions/28915913/what-is-use-of-tuple-getstringbyfieldabc-in-storm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!