You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@apex.apache.org by Jaikit Jilka <jj...@leadferret.com> on 2016/09/29 22:03:07 UTC
Emit values from an array
Hello,
I am trying to emit values from an array. I am emitting using an for loop. Number of records emitted is correct but it is emitting only the last value of the array multiple times. So how to emit different values of array.
int i =0;
for (int j = 0;j<cares.length;j++) {
pojo.setID(id);
pojo.seturl(url);
pojo.setPosition(i);
pojo.setCares(cares[j]);
i++;
CaresOut.emit(pojo);
}
Thank you,
Jaikit Jilka
Re: Emit values from an array
Posted by Sandesh Hegde <sa...@datatorrent.com>.
Create new object, for every emit.
On Thu, Sep 29, 2016 at 3:02 PM Jaikit Jilka <jj...@leadferret.com> wrote:
> Hello,
>
> I am trying to emit values from an array. I am emitting using an for loop.
> Number of records emitted is correct but it is emitting only the last value
> of the array multiple times. So how to emit different values of array.
>
> int i =0;
> for (int j = 0;j<cares.length;j++) {
>
> pojo.setID(id);
> pojo.seturl(url);
> pojo.setPosition(i);
> pojo.setCares(cares[j]);
> i++;
> CaresOut.emit(pojo);
> }
>
>
> Thank you,
>
> Jaikit Jilka
>
Re: Emit values from an array
Posted by Jaikit Jilka <jj...@leadferret.com>.
Hello,
Creating a new object everytime worked.
Thank You,
Jaikit Jilka
----- Original Message -----
From: hsy541@gmail.com
To: "users" <us...@apex.apache.org>
Sent: Friday, September 30, 2016 8:48:07 AM
Subject: Re: Emit values from an array
Is you pojo a shared object? I think you need to create new pojo every time.
Regards,
Siyuan
On Thu, Sep 29, 2016 at 3:03 PM, Jaikit Jilka <jj...@leadferret.com> wrote:
> Hello,
>
> I am trying to emit values from an array. I am emitting using an for loop.
> Number of records emitted is correct but it is emitting only the last value
> of the array multiple times. So how to emit different values of array.
>
> int i =0;
> for (int j = 0;j<cares.length;j++) {
>
> pojo.setID(id);
> pojo.seturl(url);
> pojo.setPosition(i);
> pojo.setCares(cares[j]);
> i++;
> CaresOut.emit(pojo);
> }
>
>
> Thank you,
>
> Jaikit Jilka
>
Re: Emit values from an array
Posted by "hsy541@gmail.com" <hs...@gmail.com>.
Is you pojo a shared object? I think you need to create new pojo every time.
Regards,
Siyuan
On Thu, Sep 29, 2016 at 3:03 PM, Jaikit Jilka <jj...@leadferret.com> wrote:
> Hello,
>
> I am trying to emit values from an array. I am emitting using an for loop.
> Number of records emitted is correct but it is emitting only the last value
> of the array multiple times. So how to emit different values of array.
>
> int i =0;
> for (int j = 0;j<cares.length;j++) {
>
> pojo.setID(id);
> pojo.seturl(url);
> pojo.setPosition(i);
> pojo.setCares(cares[j]);
> i++;
> CaresOut.emit(pojo);
> }
>
>
> Thank you,
>
> Jaikit Jilka
>