Thanks Dylan for the help. It helped me a lot.
On 18-Apr-2015 10:43 am, "Dylan Hutchison" <[email protected]> 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<Long> encoder = new 
> LongCombiner.StringEncoder();
>   private Key emitKey;
>   private Value emitValue;
>
>   @Override
>   public void seek(Range range, Collection<ByteSequence> 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 <
> [email protected]> 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, <[email protected]> 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" <[email protected]>
>>> *To: *[email protected]
>>> *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
>>>
>>>
>

Reply via email to