Hadoop::Streaming::Reducer::Input::Iterator - Collects values for each key together with an iterator interface


Hadoop-Streaming documentation Contained in the Hadoop-Streaming distribution.

Index


Code Index:

NAME

Top

Hadoop::Streaming::Reducer::Input::Iterator - Collects values for each key together with an iterator interface

VERSION

Top

version 0.110030

METHODS

Top

has_next

    $Iterator->has_next();

Checks if the iterator has a next_key. Returns 1 if there is another key in the input iterator.

next

    $Iterator->next();

Returns the key and value iterator for the next key. Discards any remaining values from the current key.

Moves the iterator to the next key value, and returns the output of retval( $key, $value);

retval

    $Iterator->retval($key );
    $Iterator->retval($key, $value);

Returns an two element array containing the key and a Hadoop::Streaming::Reducer::Input::ValuesIterator initialized with the given value as the first element.

( $key, $ValueIterator)

AUTHORS

Top

COPYRIGHT AND LICENSE

Top


Hadoop-Streaming documentation Contained in the Hadoop-Streaming distribution.

package Hadoop::Streaming::Reducer::Input::Iterator;
BEGIN {
  $Hadoop::Streaming::Reducer::Input::Iterator::VERSION = '0.110030';
}
use Moose;
with 'Hadoop::Streaming::Role::Iterator';

use Hadoop::Streaming::Reducer::Input::ValuesIterator;

#ABSTRACT: Collects values for each key together with an iterator interface

has input => (
    is       => 'ro',
    isa      => 'Hadoop::Streaming::Reducer::Input',
    required => 1,
);

has current_key => (
    is   => 'rw',
    does => 'Str'
);


sub has_next {
    my $self = shift;
    return if not defined $self->input->next_key;
    1;
}


sub next {
    my $self = shift;

    if ( not defined $self->current_key ) {
        $self->current_key($self->input->next_key);
        return $self->retval( $self->current_key );
    }

    if ($self->current_key ne $self->input->next_key) {
        $self->current_key($self->input->next_key);
        return $self->retval( $self->current_key );
    }

    my ($key, $value);
    do {
        ($key, $value) = $self->input->each or return;
    } while ($self->current_key eq $key);
    $self->current_key( $key );

    return $self->retval($key, $value);
}


sub retval {
    my ($self, $key, $value) = @_;
    return (
        $key,
        Hadoop::Streaming::Reducer::Input::ValuesIterator->new(
            input_iter => $self,
            first      => $value,
        ),
    );
}

__PACKAGE__->meta->make_immutable;

1;

__END__