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 <[email protected]
> 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 <
> [email protected]> 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 <[email protected]>
>> wrote:
>>
>>> Can you explain just what it is you want your code to do?
>>>
>>> From: Sai Dilip Reddy Kiralam <[email protected]>
>>> Reply-To: "[email protected]" <[email protected]>
>>> Date: Saturday, March 5, 2016 at 1:10 AM
>>> To: "[email protected]" <[email protected]>
>>> 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 <[email protected]>
>>> 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 <[email protected]>
>>>> Reply-To: "[email protected]" <[email protected]>
>>>> Date: Tuesday, March 1, 2016 at 6:16 AM
>>>> To: "[email protected]" <[email protected]>
>>>> 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.
>>>>
>>>
>>>
>>
>

Reply via email to