Return-Path: X-Original-To: apmail-accumulo-user-archive@www.apache.org Delivered-To: apmail-accumulo-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 253BF17B18 for ; Mon, 27 Apr 2015 17:23:44 +0000 (UTC) Received: (qmail 81050 invoked by uid 500); 27 Apr 2015 17:23:44 -0000 Delivered-To: apmail-accumulo-user-archive@accumulo.apache.org Received: (qmail 80998 invoked by uid 500); 27 Apr 2015 17:23:43 -0000 Mailing-List: contact user-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@accumulo.apache.org Delivered-To: mailing list user@accumulo.apache.org Received: (qmail 80988 invoked by uid 99); 27 Apr 2015 17:23:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2015 17:23:43 +0000 X-ASF-Spam-Status: No, hits=3.4 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (athena.apache.org: transitioning domain of vaibhav.thapliyal.91@gmail.com does not designate 54.191.145.13 as permitted sender) Received: from [54.191.145.13] (HELO mx1-us-west.apache.org) (54.191.145.13) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2015 17:23:38 +0000 Received: from mail-ie0-f171.google.com (mail-ie0-f171.google.com [209.85.223.171]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 4822420659 for ; Mon, 27 Apr 2015 17:23:18 +0000 (UTC) Received: by iecrt8 with SMTP id rt8so131558616iec.0 for ; Mon, 27 Apr 2015 10:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=KKFxr410lSwZXlImDnoU3n4WLKFkz/A4hpBWcmOE6TA=; b=DXPFauAWyLAaNSN0nQC0Vr6z675IePbWHihdLoe62v/RCqiliUeM7uaW0sz7fhy/5/ BOemNm+uinEzINxnEySIQ/mNx47FHhroVdYLMcQkmqjkAmkqP30vD/8jbROOZ4FYwpNx ICcswUk6ivMUtsKSi3J9xAo2TrQopqfJDXb7h/9iCGivSH4aZKpLWIdELid7yK6QvhTC i61tlrOs4QcEVZ1a9eEzE/k2+8GHBKooyHYqGzseHBWiQ9UE+AuJYziUftR/k6JV6/Zj twq/vQLP87TkK7KSwv67qU9RcKY7qY7W3Z23asogvR8p31NsY15/VGajBDpFgrl9PZlQ QU5A== MIME-Version: 1.0 X-Received: by 10.50.221.98 with SMTP id qd2mr14698226igc.37.1430155346611; Mon, 27 Apr 2015 10:22:26 -0700 (PDT) Received: by 10.36.127.69 with HTTP; Mon, 27 Apr 2015 10:22:26 -0700 (PDT) Received: by 10.36.127.69 with HTTP; Mon, 27 Apr 2015 10:22:26 -0700 (PDT) In-Reply-To: References: <55310192.3040002@orkash.com> <1564642205.8516289.1429276148309.JavaMail.zimbra@comcast.net> Date: Mon, 27 Apr 2015 22:52:26 +0530 Message-ID: Subject: Re: Custom Iterator output From: vaibhav thapliyal To: user@accumulo.apache.org Content-Type: multipart/alternative; boundary=001a11347f2068b6860514b7fdf1 X-Virus-Checked: Checked by ClamAV on apache.org --001a11347f2068b6860514b7fdf1 Content-Type: text/plain; charset=UTF-8 Thanks Dylan for the help. It helped me a lot. On 18-Apr-2015 10:43 am, "Dylan Hutchison" wrote: > Hi Vaibhav, > > It sounds like you want to emit a single value that is a function of all > the entries in the parent iterator. In that case, the following template > should solve your problem, using the example of summing Values interpreted > as Longs: > > /** > * Emit one value that is a function of entries from the parent iterator. > */ > public class SingleOutputIterator extends WrappingIterator { > private static final TypedValueCombiner.Encoder encoder = new LongCombiner.StringEncoder(); > private Key emitKey; > private Value emitValue; > > @Override > public void seek(Range range, Collection columnFamilies, boolean inclusive) throws IOException { > super.seek(range, columnFamilies, inclusive); > myFunction(); > } > > /** > * Reads all entries from the parent iterator, computing the value you want to emit. > * Example given is summing the Values of parent entries, interpreted as Longs. > */ > private void myFunction() throws IOException { > Long val = 0l; > while (super.hasTop()) { > val += encoder.decode(super.getTopValue().get()); > super.next(); > } > emitKey = new Key(); // replace this with the key you want to emit > emitValue = new Value(encoder.encode(val)); > } > > @Override > public Key getTopKey() { > return emitKey; > } > > @Override > public Value getTopValue() { > return emitValue; > } > > @Override > public boolean hasTop() { > return emitKey != null; > } > > @Override > public void next() throws IOException { > emitKey = null; > emitValue = null; > } > } > > Regards, > Dylan Hutchison > > > > On Fri, Apr 17, 2015 at 8:05 PM, vaibhav thapliyal < > vaibhav.thapliyal.91@gmail.com> wrote: > >> Hi, >> >> I also had this query that might be similar to shweta. >> >> What I want to do is process the key value pairs that I get from >> getTopKey() and getTopValue() methods and I want to output that value. >> >> Currently I was writing these values to tables from inside the iterators, >> but I read in the new manual that says that doing this isn't a good >> practice. >> >> For eg: >> >> If I have these entries in my table: >> >> 1 cf1:cq1 value1 >> 2 cf2:cq2 value2 >> 3 cf3:cq3 value3 >> And suppose I sum the values(or do any opeation) of the row ids using the >> values that I get from the getTopKey().getRow() function and store this sum >> in a variable called "sum". >> >> So I want to output this variable. How do I go about this? >> >> Thanks >> Vaibhav >> On 17-Apr-2015 6:40 pm, wrote: >> >>> via the getTopKey() and getTopValue() methods. [1] should be a simple >>> example. >>> >>> [1] >>> https://git-wip-us.apache.org/repos/asf?p=accumulo.git;a=blob;f=core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java;h=043a729a778fc34d2ee87a0227056ffac81b7fe7;hb=refs/heads/master >>> >>> ------------------------------ >>> *From: *"shweta.agrawal" >>> *To: *user@accumulo.apache.org >>> *Sent: *Friday, April 17, 2015 8:50:26 AM >>> *Subject: *Custom Iterator output >>> >>> Hi, >>> >>> I am working on custom iterator. I want to know, how do i get the output >>> from the custom iterators? >>> >>> Thanks and Regards >>> Shweta >>> >>> > --001a11347f2068b6860514b7fdf1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Thanks Dylan for the help. It helped me a lot.

On 18-Apr-2015 10:43 am, "Dylan Hutchison&q= uot; <dhutchis@mit.edu> wrote= :
H= i Vaibhav,

It sounds like you want to emit a single valu= e that is a function of all the entries in the parent iterator.=C2=A0 In th= at case, the following template should solve your problem, using the exampl= e of summing Values interpreted as Longs:

/**
* Emit one value that is a function of entries from the par= ent iterator.
*/
public class SingleOutputIterator extends = WrappingIterator {
private stati= c final TypedValueCombiner.Encoder<Long> encoder =3D new LongCombiner.StringEncoder();
pri= vate Key emitKey;
private Value emitVa= lue;

<= /span>@Override
p= ublic void seek(Range = range, Collection<ByteSeque= nce> columnFamilies, boolean inclusive) throws IOExceptio= n {
super.seek(range,
columnFamilies, inclusive);
myFunction(= );
}

/**
* Reads all entries from the parent iterator, computing the valu= e you want to emit.
* Example given is summing the Values of parent entries, inter= preted as Longs.
*/
private void myFunction
() throws IOException {
Long val =3D 0l;
while (super.hasTop()) {
val +=3D = encoder.dec= ode(super.getTopValue().get())= ;
super.next();
}
emitKey
=3D new Key(); // replace this with the key yo= u want to emit
= emitValue =3D new Value(encoder.encode(val));
}
@Override
= public Key getTopKey()= {
return emitKey;
}

= @Override
public = Value getTopValue() {<= br> return emitValue;
}

@Override
public boo= lean hasTop() {
= return emitKey !=3D = null;
}

<= span style=3D"color:rgb(187,181,41)">@Override
public v= oid next() throws IOException {
emitKey =3D null;
= emitValue =3D null;
}
}
Regards,
Dylan Hutchison
<= div>


On Fri, Apr 17, 2015 at 8:05 PM, vaibhav thapliyal <vaibhav.thapliyal.91@gmail.com> wrote:

Hi,

I also had this query that might be similar to shweta.

What I want to do is process the key value pairs that I get = from getTopKey() and getTopValue() methods and I want to output that value.=

Currently I was writing these values to tables from inside t= he iterators, but I read in the new manual that says that doing this isn= 9;t a good practice.

For eg:

If I have these entries in my table:

1 cf1:cq1 value1
2 cf2:cq2 value2
3 cf3:cq3 value3
And suppose I sum the values(or do any opeation) of the row ids using the v= alues that I get from the getTopKey().getRow() function and store this sum = in a variable called "sum".

So I want to output this variable. How do I go about this? <= /p>

Thanks
Vaibhav

On 17-Apr-2015 6:40 pm, <dlmarion@comcast.net> wrote:<= br type=3D"attribution">
via the getTopKey() and= getTopValue() methods. [1] should be a simple example.

<= /div>


From: "shweta.agraw= al" <shweta.agrawal@orkash.com>
To: user@accumulo.apache.org
Sent= : Friday, April 17, 2015 8:50:26 AM
Subject: Custom Iterator = output

Hi,

I am working on custom itera= tor. I want to know, how do i get the output
from the custom iterators?=

Thanks and Regards
Shweta


--001a11347f2068b6860514b7fdf1--