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