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

2019-08-29 06:47发布

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.

2条回答
我命由我不由天
2楼-- · 2019-08-29 07:24

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

查看更多
Ridiculous、
3楼-- · 2019-08-29 07:28

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.

查看更多
登录 后发表回答