You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@storm.apache.org by Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com> on 2016/03/01 13:16:43 UTC

How to emit the values in a for-each loop

I'm having the a string values which are appended so i used the for each
loop and sliptted them and emit them with in the for each loop.if I'm
getting id string v="1,2,3";
I'm using for each and emitting the id in for loop itself.
next when I Tried to emit the value of other string which is a appended one
and declaring it as field.I getting the error saying

java.lang.IllegalArgumentException: Tuple created with wrong number of
fields. Expected 2 fields but got 1 fields at
backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at
backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739)
at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763)
at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203)
at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63)
at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101)
at test.bolts.TInserts.execute(TInsert.java:264)



Here is my bolt code.

 public void execute(Tuple tuple) {
   try {String screenname=tuple.getStringByField("s_name");
    String mentionname=tuple.getStringByField("n_name");
    String mentionid=tuple.getStringByField("n_id");

                 if(mentionid != null && !mentionid.isEmpty()){
                     for(String id:mentionid.split(",")){
                        id = id.trim();
                          this.collector.emit(new Values(id));
 this.collector.ack(tuple);
 }//for close
 }//if condtion for id
 if(mentionname != null && !mentionname.isEmpty()){
                     for(String mns:mentionname.split(",")){
                        mns = mns.trim();
                          this.collector.emit(new
Values(mns));this.collector.ack(tuple);
   }//for close
 }//if condtion for mentionname

  } //if close
    }
             catch (Exception e) {
           this.collector.reportError(e);
          this.collector.fail(tuple);
             }
       }

@Override
   public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw
any   exception if i emit only id(1st for)
    outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}

please give the suggestion that I need to change in the bolt code.

Re: How to emit the values in a for-each loop

Posted by Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>.
  I did not get the point of setting up and emitting on two different
channels.Can you explain with sample code
snippet .

Thank you



On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>
wrote:

> Since you are declaring that you emit two values you need to emit two
> values any time you call emit.  If you want to emit two totally different
> things at different times (ids and nms) you should set up the bolt to emit
> on two different channels.  You should also only “ack” your tuple once, at
> the end of all your processing.
>
> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
> Date: Tuesday, March 1, 2016 at 6:16 AM
> To: "user@storm.apache.org" <us...@storm.apache.org>
> Subject: How to emit the values in a for-each loop
>
> I'm having the a string values which are appended so i used the for each
> loop and sliptted them and emit them with in the for each loop.if I'm
> getting id string v="1,2,3";
> I'm using for each and emitting the id in for loop itself.
> next when I Tried to emit the value of other string which is a appended
> one and declaring it as field.I getting the error saying
>
> java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)
>
>
>
> Here is my bolt code.
>
>  public void execute(Tuple tuple) {
>    try {String screenname=tuple.getStringByField("s_name");
>     String mentionname=tuple.getStringByField("n_name");
>     String mentionid=tuple.getStringByField("n_id");
>
>                  if(mentionid != null && !mentionid.isEmpty()){
>                      for(String id:mentionid.split(",")){
>                         id = id.trim();
>                           this.collector.emit(new Values(id));
>  this.collector.ack(tuple);
>  }//for close
>  }//if condtion for id
>  if(mentionname != null && !mentionname.isEmpty()){
>                      for(String mns:mentionname.split(",")){
>                         mns = mns.trim();
>                           this.collector.emit(new Values(mns));this.collector.ack(tuple);
>    }//for close
>  }//if condtion for mentionname
>
>   } //if close
>     }
>              catch (Exception e) {
>            this.collector.reportError(e);
>           this.collector.fail(tuple);
>              }
>        }
>
> @Override
>    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
>     outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}
>
> please give the suggestion that I need to change in the bolt code.
>

Re: How to emit the values in a for-each loop

Posted by "Aaron.Dossett" <Aa...@target.com>.
Then you need to declare both of the values you are going to emit:


outputFieldsDeclarer.declare(new Fields("id","mns"));

And then programmatically find the pairs you want to emit and make a call to emit() with both values.

From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>>
Reply-To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Date: Tuesday, March 8, 2016 at 12:22 AM
To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Subject: Re: How to emit the values in a for-each loop

I want to emit "id" and "mns" at same time in single emit .right now I can emit them individually in a for each loop.
Hope you got my problem.



Best regards,
K.Sai Dilip Reddy,
Software Engineer - Hadoop Trainee,
2-39, Old SBI Road,
Sri Nagar Colony,
Gannavaram - 521101.
www.aadhya-analytics.com<http://www.aadhya-analytics.com/>.
[Inline image 1]

On Mon, Mar 7, 2016 at 8:18 PM, Aaron.Dossett <Aa...@target.com>> wrote:
Can you explain just what it is you want your code to do?

From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>>
Reply-To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Date: Saturday, March 5, 2016 at 1:10 AM
To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Subject: Re: How to emit the values in a for-each loop

HI Aaron

I did not get the point of setting up two emitting on two different channels.Can you explain with sample code snippet .
Thank you


On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>> wrote:
Since you are declaring that you emit two values you need to emit two values any time you call emit.  If you want to emit two totally different things at different times (ids and nms) you should set up the bolt to emit on two different channels.  You should also only "ack" your tuple once, at the end of all your processing.

From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>>
Reply-To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Date: Tuesday, March 1, 2016 at 6:16 AM
To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Subject: How to emit the values in a for-each loop

I'm having the a string values which are appended so i used the for each loop and sliptted them and emit them with in the for each loop.if I'm getting id string v="1,2,3";
I'm using for each and emitting the id in for loop itself.
next when I Tried to emit the value of other string which is a appended one and declaring it as field.I getting the error saying


java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)


Here is my bolt code.


 public void execute(Tuple tuple) {
   try {String screenname=tuple.getStringByField("s_name");
    String mentionname=tuple.getStringByField("n_name");
    String mentionid=tuple.getStringByField("n_id");

                 if(mentionid != null && !mentionid.isEmpty()){
                     for(String id:mentionid.split(",")){
                        id = id.trim();
                          this.collector.emit(new Values(id));
 this.collector.ack(tuple);
 }//for close
 }//if condtion for id
 if(mentionname != null && !mentionname.isEmpty()){
                     for(String mns:mentionname.split(",")){
                        mns = mns.trim();
                          this.collector.emit(new Values(mns));this.collector.ack(tuple);
   }//for close
 }//if condtion for mentionname

  } //if close
    }
             catch (Exception e) {
           this.collector.reportError(e);
          this.collector.fail(tuple);
             }
       }


@Override
   public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
    outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}

please give the suggestion that I need to change in the bolt code.



Re: How to emit the values in a for-each loop

Posted by Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>.
Hi sid,

I tried with the modification lines.when I ran the code it said to initialize
the values so kept null.

Values idValue=null, nameValue=null;
then when I ran the code it thrown me the following exception

java.lang.ClassCastException: backtype.storm.tuple.Values cannot be cast to
java.lang.Long at
backtype.storm.tuple.TupleImpl.getLongByField(TupleImpl.java:161) at
com.aail.dao.SimpleJdbcMapper.getColumns(SimpleJdbcMapper.java:49) at
com.aail.storm.bolts.Story_tags.execute(Story_tags.java:83) at

Here the code snippet tried out with your lines



public void execute(Tuple tuple) {
   try {
String screenname=tuple.getStringByField("s_name");
    String mentionname=tuple.getStringByField("n_name");
    String mentionid=tuple.getStringByField("n_id");

                 if(mentionid != null && !mentionid.isEmpty()){
                     for(String id:mentionid.split(",")){
                        id = id.trim();
		long story_tag_id=Long.parseLong(id);//Casting error
                          this.collector.emit(new Values(id));
 this.collector.ack(tuple);
 }//for close
 }//if condtion for id

  }
             catch (Exception e) {
           this.collector.reportError(e);
          this.collector.fail(tuple);
             }
       }




On Tue, Mar 8, 2016 at 1:25 PM, Siddartha Guthikonda <siddartha.gu@gmail.com
> wrote:

> What happens if you do something like this.
>
> https://gist.github.com/sidhhu/1e7062607e38174e95cf
>
> Thanks
> Sid
>
> On Mon, Mar 7, 2016 at 10:22 PM, Sai Dilip Reddy Kiralam <
> dkiralam@aadhya-analytics.com> wrote:
>
>> I want to emit "id" and "mns" at same time in single emit .right now I
>> can emit them individually in a for each loop.
>> Hope you got my problem.
>>
>>
>>
>> *Best regards,*
>>
>> *K.Sai Dilip Reddy,*
>>
>>
>> *Software Engineer - Hadoop Trainee,2-39, Old SBI Road, Sri Nagar
>> Colony, Gannavaram - 521101.*
>> *www.aadhya-analytics.com <http://www.aadhya-analytics.com/>.*
>> *[image: Inline image 1]*
>>
>> On Mon, Mar 7, 2016 at 8:18 PM, Aaron.Dossett <Aa...@target.com>
>> wrote:
>>
>>> Can you explain just what it is you want your code to do?
>>>
>>> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
>>> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
>>> Date: Saturday, March 5, 2016 at 1:10 AM
>>> To: "user@storm.apache.org" <us...@storm.apache.org>
>>> Subject: Re: How to emit the values in a for-each loop
>>>
>>> HI Aaron
>>>
>>> I did not get the point of setting up two emitting on two different
>>> channels.Can you explain with sample code snippet .
>>> Thank you
>>>
>>>
>>> On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>
>>> wrote:
>>>
>>>> Since you are declaring that you emit two values you need to emit two
>>>> values any time you call emit.  If you want to emit two totally different
>>>> things at different times (ids and nms) you should set up the bolt to emit
>>>> on two different channels.  You should also only “ack” your tuple once, at
>>>> the end of all your processing.
>>>>
>>>> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
>>>> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
>>>> Date: Tuesday, March 1, 2016 at 6:16 AM
>>>> To: "user@storm.apache.org" <us...@storm.apache.org>
>>>> Subject: How to emit the values in a for-each loop
>>>>
>>>> I'm having the a string values which are appended so i used the for
>>>> each loop and sliptted them and emit them with in the for each loop.if I'm
>>>> getting id string v="1,2,3";
>>>> I'm using for each and emitting the id in for loop itself.
>>>> next when I Tried to emit the value of other string which is a appended
>>>> one and declaring it as field.I getting the error saying
>>>>
>>>> java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)
>>>>
>>>>
>>>>
>>>> Here is my bolt code.
>>>>
>>>>  public void execute(Tuple tuple) {
>>>>    try {String screenname=tuple.getStringByField("s_name");
>>>>     String mentionname=tuple.getStringByField("n_name");
>>>>     String mentionid=tuple.getStringByField("n_id");
>>>>
>>>>                  if(mentionid != null && !mentionid.isEmpty()){
>>>>                      for(String id:mentionid.split(",")){
>>>>                         id = id.trim();
>>>>                           this.collector.emit(new Values(id));
>>>>  this.collector.ack(tuple);
>>>>  }//for close
>>>>  }//if condtion for id
>>>>  if(mentionname != null && !mentionname.isEmpty()){
>>>>                      for(String mns:mentionname.split(",")){
>>>>                         mns = mns.trim();
>>>>                           this.collector.emit(new Values(mns));this.collector.ack(tuple);
>>>>    }//for close
>>>>  }//if condtion for mentionname
>>>>
>>>>   } //if close
>>>>     }
>>>>              catch (Exception e) {
>>>>            this.collector.reportError(e);
>>>>           this.collector.fail(tuple);
>>>>              }
>>>>        }
>>>>
>>>> @Override
>>>>    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
>>>>     outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}
>>>>
>>>> please give the suggestion that I need to change in the bolt code.
>>>>
>>>
>>>
>>
>

Re: How to emit the values in a for-each loop

Posted by Siddartha Guthikonda <si...@gmail.com>.
What happens if you do something like this.

https://gist.github.com/sidhhu/1e7062607e38174e95cf

Thanks
Sid

On Mon, Mar 7, 2016 at 10:22 PM, Sai Dilip Reddy Kiralam <
dkiralam@aadhya-analytics.com> wrote:

> I want to emit "id" and "mns" at same time in single emit .right now I can
> emit them individually in a for each loop.
> Hope you got my problem.
>
>
>
> *Best regards,*
>
> *K.Sai Dilip Reddy,*
>
>
> *Software Engineer - Hadoop Trainee,2-39, Old SBI Road, Sri Nagar
> Colony, Gannavaram - 521101.*
> *www.aadhya-analytics.com <http://www.aadhya-analytics.com/>.*
> *[image: Inline image 1]*
>
> On Mon, Mar 7, 2016 at 8:18 PM, Aaron.Dossett <Aa...@target.com>
> wrote:
>
>> Can you explain just what it is you want your code to do?
>>
>> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
>> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
>> Date: Saturday, March 5, 2016 at 1:10 AM
>> To: "user@storm.apache.org" <us...@storm.apache.org>
>> Subject: Re: How to emit the values in a for-each loop
>>
>> HI Aaron
>>
>> I did not get the point of setting up two emitting on two different
>> channels.Can you explain with sample code snippet .
>> Thank you
>>
>>
>> On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>
>> wrote:
>>
>>> Since you are declaring that you emit two values you need to emit two
>>> values any time you call emit.  If you want to emit two totally different
>>> things at different times (ids and nms) you should set up the bolt to emit
>>> on two different channels.  You should also only “ack” your tuple once, at
>>> the end of all your processing.
>>>
>>> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
>>> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
>>> Date: Tuesday, March 1, 2016 at 6:16 AM
>>> To: "user@storm.apache.org" <us...@storm.apache.org>
>>> Subject: How to emit the values in a for-each loop
>>>
>>> I'm having the a string values which are appended so i used the for each
>>> loop and sliptted them and emit them with in the for each loop.if I'm
>>> getting id string v="1,2,3";
>>> I'm using for each and emitting the id in for loop itself.
>>> next when I Tried to emit the value of other string which is a appended
>>> one and declaring it as field.I getting the error saying
>>>
>>> java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)
>>>
>>>
>>>
>>> Here is my bolt code.
>>>
>>>  public void execute(Tuple tuple) {
>>>    try {String screenname=tuple.getStringByField("s_name");
>>>     String mentionname=tuple.getStringByField("n_name");
>>>     String mentionid=tuple.getStringByField("n_id");
>>>
>>>                  if(mentionid != null && !mentionid.isEmpty()){
>>>                      for(String id:mentionid.split(",")){
>>>                         id = id.trim();
>>>                           this.collector.emit(new Values(id));
>>>  this.collector.ack(tuple);
>>>  }//for close
>>>  }//if condtion for id
>>>  if(mentionname != null && !mentionname.isEmpty()){
>>>                      for(String mns:mentionname.split(",")){
>>>                         mns = mns.trim();
>>>                           this.collector.emit(new Values(mns));this.collector.ack(tuple);
>>>    }//for close
>>>  }//if condtion for mentionname
>>>
>>>   } //if close
>>>     }
>>>              catch (Exception e) {
>>>            this.collector.reportError(e);
>>>           this.collector.fail(tuple);
>>>              }
>>>        }
>>>
>>> @Override
>>>    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
>>>     outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}
>>>
>>> please give the suggestion that I need to change in the bolt code.
>>>
>>
>>
>

Re: How to emit the values in a for-each loop

Posted by Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>.
I want to emit "id" and "mns" at same time in single emit .right now I can
emit them individually in a for each loop.
Hope you got my problem.



*Best regards,*

*K.Sai Dilip Reddy,*


*Software Engineer - Hadoop Trainee,2-39, Old SBI Road, Sri Nagar
Colony, Gannavaram - 521101.*
*www.aadhya-analytics.com <http://www.aadhya-analytics.com/>.*
*[image: Inline image 1]*

On Mon, Mar 7, 2016 at 8:18 PM, Aaron.Dossett <Aa...@target.com>
wrote:

> Can you explain just what it is you want your code to do?
>
> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
> Date: Saturday, March 5, 2016 at 1:10 AM
> To: "user@storm.apache.org" <us...@storm.apache.org>
> Subject: Re: How to emit the values in a for-each loop
>
> HI Aaron
>
> I did not get the point of setting up two emitting on two different
> channels.Can you explain with sample code snippet .
> Thank you
>
>
> On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>
> wrote:
>
>> Since you are declaring that you emit two values you need to emit two
>> values any time you call emit.  If you want to emit two totally different
>> things at different times (ids and nms) you should set up the bolt to emit
>> on two different channels.  You should also only “ack” your tuple once, at
>> the end of all your processing.
>>
>> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
>> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
>> Date: Tuesday, March 1, 2016 at 6:16 AM
>> To: "user@storm.apache.org" <us...@storm.apache.org>
>> Subject: How to emit the values in a for-each loop
>>
>> I'm having the a string values which are appended so i used the for each
>> loop and sliptted them and emit them with in the for each loop.if I'm
>> getting id string v="1,2,3";
>> I'm using for each and emitting the id in for loop itself.
>> next when I Tried to emit the value of other string which is a appended
>> one and declaring it as field.I getting the error saying
>>
>> java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)
>>
>>
>>
>> Here is my bolt code.
>>
>>  public void execute(Tuple tuple) {
>>    try {String screenname=tuple.getStringByField("s_name");
>>     String mentionname=tuple.getStringByField("n_name");
>>     String mentionid=tuple.getStringByField("n_id");
>>
>>                  if(mentionid != null && !mentionid.isEmpty()){
>>                      for(String id:mentionid.split(",")){
>>                         id = id.trim();
>>                           this.collector.emit(new Values(id));
>>  this.collector.ack(tuple);
>>  }//for close
>>  }//if condtion for id
>>  if(mentionname != null && !mentionname.isEmpty()){
>>                      for(String mns:mentionname.split(",")){
>>                         mns = mns.trim();
>>                           this.collector.emit(new Values(mns));this.collector.ack(tuple);
>>    }//for close
>>  }//if condtion for mentionname
>>
>>   } //if close
>>     }
>>              catch (Exception e) {
>>            this.collector.reportError(e);
>>           this.collector.fail(tuple);
>>              }
>>        }
>>
>> @Override
>>    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
>>     outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}
>>
>> please give the suggestion that I need to change in the bolt code.
>>
>
>

Re: How to emit the values in a for-each loop

Posted by "Aaron.Dossett" <Aa...@target.com>.
Can you explain just what it is you want your code to do?

From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>>
Reply-To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Date: Saturday, March 5, 2016 at 1:10 AM
To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Subject: Re: How to emit the values in a for-each loop

HI Aaron

I did not get the point of setting up two emitting on two different channels.Can you explain with sample code snippet .
Thank you


On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>> wrote:
Since you are declaring that you emit two values you need to emit two values any time you call emit.  If you want to emit two totally different things at different times (ids and nms) you should set up the bolt to emit on two different channels.  You should also only "ack" your tuple once, at the end of all your processing.

From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>>
Reply-To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Date: Tuesday, March 1, 2016 at 6:16 AM
To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Subject: How to emit the values in a for-each loop

I'm having the a string values which are appended so i used the for each loop and sliptted them and emit them with in the for each loop.if I'm getting id string v="1,2,3";
I'm using for each and emitting the id in for loop itself.
next when I Tried to emit the value of other string which is a appended one and declaring it as field.I getting the error saying


java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)


Here is my bolt code.


 public void execute(Tuple tuple) {
   try {String screenname=tuple.getStringByField("s_name");
    String mentionname=tuple.getStringByField("n_name");
    String mentionid=tuple.getStringByField("n_id");

                 if(mentionid != null && !mentionid.isEmpty()){
                     for(String id:mentionid.split(",")){
                        id = id.trim();
                          this.collector.emit(new Values(id));
 this.collector.ack(tuple);
 }//for close
 }//if condtion for id
 if(mentionname != null && !mentionname.isEmpty()){
                     for(String mns:mentionname.split(",")){
                        mns = mns.trim();
                          this.collector.emit(new Values(mns));this.collector.ack(tuple);
   }//for close
 }//if condtion for mentionname

  } //if close
    }
             catch (Exception e) {
           this.collector.reportError(e);
          this.collector.fail(tuple);
             }
       }


@Override
   public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
    outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}

please give the suggestion that I need to change in the bolt code.


Re: How to emit the values in a for-each loop

Posted by Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>.
HI Aaron

I did not get the point of setting up two emitting on two different
channels.Can you explain with sample code snippet .
Thank you


On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>
wrote:

> Since you are declaring that you emit two values you need to emit two
> values any time you call emit.  If you want to emit two totally different
> things at different times (ids and nms) you should set up the bolt to emit
> on two different channels.  You should also only “ack” your tuple once, at
> the end of all your processing.
>
> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
> Date: Tuesday, March 1, 2016 at 6:16 AM
> To: "user@storm.apache.org" <us...@storm.apache.org>
> Subject: How to emit the values in a for-each loop
>
> I'm having the a string values which are appended so i used the for each
> loop and sliptted them and emit them with in the for each loop.if I'm
> getting id string v="1,2,3";
> I'm using for each and emitting the id in for loop itself.
> next when I Tried to emit the value of other string which is a appended
> one and declaring it as field.I getting the error saying
>
> java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)
>
>
>
> Here is my bolt code.
>
>  public void execute(Tuple tuple) {
>    try {String screenname=tuple.getStringByField("s_name");
>     String mentionname=tuple.getStringByField("n_name");
>     String mentionid=tuple.getStringByField("n_id");
>
>                  if(mentionid != null && !mentionid.isEmpty()){
>                      for(String id:mentionid.split(",")){
>                         id = id.trim();
>                           this.collector.emit(new Values(id));
>  this.collector.ack(tuple);
>  }//for close
>  }//if condtion for id
>  if(mentionname != null && !mentionname.isEmpty()){
>                      for(String mns:mentionname.split(",")){
>                         mns = mns.trim();
>                           this.collector.emit(new Values(mns));this.collector.ack(tuple);
>    }//for close
>  }//if condtion for mentionname
>
>   } //if close
>     }
>              catch (Exception e) {
>            this.collector.reportError(e);
>           this.collector.fail(tuple);
>              }
>        }
>
> @Override
>    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
>     outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}
>
> please give the suggestion that I need to change in the bolt code.
>

Re: How to emit the values in a for-each loop

Posted by Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>.
 I did not get the point of setting up  two different channels.Can you
explain with sample code snippet .
Thank you



*Best regards,*

*K.Sai Dilip Reddy,*


*Software Engineer - Hadoop Trainee,2-39, Old SBI Road, Sri Nagar
Colony, Gannavaram - 521101.*
*www.aadhya-analytics.com <http://www.aadhya-analytics.com/>.*
*[image: Inline image 1]*

On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <Aa...@target.com>
wrote:

> Since you are declaring that you emit two values you need to emit two
> values any time you call emit.  If you want to emit two totally different
> things at different times (ids and nms) you should set up the bolt to emit
> on two different channels.  You should also only “ack” your tuple once, at
> the end of all your processing.
>
> From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>
> Reply-To: "user@storm.apache.org" <us...@storm.apache.org>
> Date: Tuesday, March 1, 2016 at 6:16 AM
> To: "user@storm.apache.org" <us...@storm.apache.org>
> Subject: How to emit the values in a for-each loop
>
> I'm having the a string values which are appended so i used the for each
> loop and sliptted them and emit them with in the for each loop.if I'm
> getting id string v="1,2,3";
> I'm using for each and emitting the id in for loop itself.
> next when I Tried to emit the value of other string which is a appended
> one and declaring it as field.I getting the error saying
>
> java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)
>
>
>
> Here is my bolt code.
>
>  public void execute(Tuple tuple) {
>    try {String screenname=tuple.getStringByField("s_name");
>     String mentionname=tuple.getStringByField("n_name");
>     String mentionid=tuple.getStringByField("n_id");
>
>                  if(mentionid != null && !mentionid.isEmpty()){
>                      for(String id:mentionid.split(",")){
>                         id = id.trim();
>                           this.collector.emit(new Values(id));
>  this.collector.ack(tuple);
>  }//for close
>  }//if condtion for id
>  if(mentionname != null && !mentionname.isEmpty()){
>                      for(String mns:mentionname.split(",")){
>                         mns = mns.trim();
>                           this.collector.emit(new Values(mns));this.collector.ack(tuple);
>    }//for close
>  }//if condtion for mentionname
>
>   } //if close
>     }
>              catch (Exception e) {
>            this.collector.reportError(e);
>           this.collector.fail(tuple);
>              }
>        }
>
> @Override
>    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
>     outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}
>
> please give the suggestion that I need to change in the bolt code.
>

Re: How to emit the values in a for-each loop

Posted by "Aaron.Dossett" <Aa...@target.com>.
Since you are declaring that you emit two values you need to emit two values any time you call emit.  If you want to emit two totally different things at different times (ids and nms) you should set up the bolt to emit on two different channels.  You should also only "ack" your tuple once, at the end of all your processing.

From: Sai Dilip Reddy Kiralam <dk...@aadhya-analytics.com>>
Reply-To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Date: Tuesday, March 1, 2016 at 6:16 AM
To: "user@storm.apache.org<ma...@storm.apache.org>" <us...@storm.apache.org>>
Subject: How to emit the values in a for-each loop

I'm having the a string values which are appended so i used the for each loop and sliptted them and emit them with in the for each loop.if I'm getting id string v="1,2,3";
I'm using for each and emitting the id in for loop itself.
next when I Tried to emit the value of other string which is a appended one and declaring it as field.I getting the error saying


java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 2 fields but got 1 fields at backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) at backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at test.bolts.TInserts.execute(TInsert.java:264)


Here is my bolt code.


 public void execute(Tuple tuple) {
   try {String screenname=tuple.getStringByField("s_name");
    String mentionname=tuple.getStringByField("n_name");
    String mentionid=tuple.getStringByField("n_id");

                 if(mentionid != null && !mentionid.isEmpty()){
                     for(String id:mentionid.split(",")){
                        id = id.trim();
                          this.collector.emit(new Values(id));
 this.collector.ack(tuple);
 }//for close
 }//if condtion for id
 if(mentionname != null && !mentionname.isEmpty()){
                     for(String mns:mentionname.split(",")){
                        mns = mns.trim();
                          this.collector.emit(new Values(mns));this.collector.ack(tuple);
   }//for close
 }//if condtion for mentionname

  } //if close
    }
             catch (Exception e) {
           this.collector.reportError(e);
          this.collector.fail(tuple);
             }
       }


@Override
   public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {//   outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any   exception if i emit only id(1st for)
    outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }}

please give the suggestion that I need to change in the bolt code.