You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mrunit.apache.org by Bertrand Dechoux <de...@gmail.com> on 2012/06/14 10:31:59 UTC

Proposition for static drivers factory

Hello,

What I do now looks like :
    private MapDriver<Text, Text, Text, Text> mapDriver = new
MapDriver<Text, Text, Text, Text>(new Mapper<Text, Text, Text, Text>());

The generics are kind of redundant.
If I use the following class :

public class MRunit {

    public static <KEYIN, VALUEIN, KEYOUT, VALUEOUT> MapDriver<KEYIN,
VALUEIN, KEYOUT, VALUEOUT> drive(Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
mapper) {
        return new MapDriver<KEYIN, VALUEIN, KEYOUT, VALUEOUT>(mapper);
    }

    public static <KEYIN, VALUEIN, KEYOUT, VALUEOUT> ReduceDriver<KEYIN,
VALUEIN, KEYOUT, VALUEOUT> drive(Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
reducer) {
        return new ReduceDriver<KEYIN, VALUEIN, KEYOUT, VALUEOUT>(reducer);
    }

}

I can now write :
    private MapDriver<Text, Text, Text, Text> mapDriver = MRunit.drive(new
Mapper<Text, Text, Text, Text>());

which is clearer for me. And the best part is that I only need to care
about one ''verb' : MRUnit.drive(...). Whether it is Mapper/Reducer or
old/new API, it works, thanks to java checking the type of the argument.

I would like to have your feedbacks about it and to know if ideally it
could be added to the next version so that I won't have to keep that glue
code.

Regards

Bertrand

Re: Proposition for static drivers factory

Posted by Bertrand Dechoux <de...@gmail.com>.
Thanks. I am learning. And the more I know, the more I love MRUnit, and the
more I forget how I did work without it.

On Thu, Jun 14, 2012 at 12:43 PM, Dave Beech <db...@apache.org> wrote:

> Hi Bertrand
>
> This actually exists already - it was added in MRUNIT-43 (
> https://issues.apache.org/jira/browse/MRUNIT-43) and released in version
> 0.8.0-incubating
>
> You can create Driver classes in a very similar way to how you describe,
> e.g.
>
> MapDriver <Text, Text, Text, Text> mapDriver = MapDriver.newMapDriver();
>
> Cheers,
> Dave
>
>
> On 14 June 2012 09:31, Bertrand Dechoux <de...@gmail.com> wrote:
>
>> Hello,
>>
>> What I do now looks like :
>>     private MapDriver<Text, Text, Text, Text> mapDriver = new
>> MapDriver<Text, Text, Text, Text>(new Mapper<Text, Text, Text, Text>());
>>
>> The generics are kind of redundant.
>> If I use the following class :
>>
>> public class MRunit {
>>
>>     public static <KEYIN, VALUEIN, KEYOUT, VALUEOUT> MapDriver<KEYIN,
>> VALUEIN, KEYOUT, VALUEOUT> drive(Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
>> mapper) {
>>         return new MapDriver<KEYIN, VALUEIN, KEYOUT, VALUEOUT>(mapper);
>>     }
>>
>>     public static <KEYIN, VALUEIN, KEYOUT, VALUEOUT> ReduceDriver<KEYIN,
>> VALUEIN, KEYOUT, VALUEOUT> drive(Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
>> reducer) {
>>         return new ReduceDriver<KEYIN, VALUEIN, KEYOUT,
>> VALUEOUT>(reducer);
>>     }
>>
>> }
>>
>> I can now write :
>>     private MapDriver<Text, Text, Text, Text> mapDriver =
>> MRunit.drive(new Mapper<Text, Text, Text, Text>());
>>
>> which is clearer for me. And the best part is that I only need to care
>> about one ''verb' : MRUnit.drive(...). Whether it is Mapper/Reducer or
>> old/new API, it works, thanks to java checking the type of the argument.
>>
>> I would like to have your feedbacks about it and to know if ideally it
>> could be added to the next version so that I won't have to keep that glue
>> code.
>>
>> Regards
>>
>> Bertrand
>>
>
>


-- 
Bertrand Dechoux

Re: Proposition for static drivers factory

Posted by Dave Beech <db...@apache.org>.
Hi Bertrand

This actually exists already - it was added in MRUNIT-43 (
https://issues.apache.org/jira/browse/MRUNIT-43) and released in version
0.8.0-incubating

You can create Driver classes in a very similar way to how you describe,
e.g.

MapDriver <Text, Text, Text, Text> mapDriver = MapDriver.newMapDriver();

Cheers,
Dave

On 14 June 2012 09:31, Bertrand Dechoux <de...@gmail.com> wrote:

> Hello,
>
> What I do now looks like :
>     private MapDriver<Text, Text, Text, Text> mapDriver = new
> MapDriver<Text, Text, Text, Text>(new Mapper<Text, Text, Text, Text>());
>
> The generics are kind of redundant.
> If I use the following class :
>
> public class MRunit {
>
>     public static <KEYIN, VALUEIN, KEYOUT, VALUEOUT> MapDriver<KEYIN,
> VALUEIN, KEYOUT, VALUEOUT> drive(Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
> mapper) {
>         return new MapDriver<KEYIN, VALUEIN, KEYOUT, VALUEOUT>(mapper);
>     }
>
>     public static <KEYIN, VALUEIN, KEYOUT, VALUEOUT> ReduceDriver<KEYIN,
> VALUEIN, KEYOUT, VALUEOUT> drive(Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
> reducer) {
>         return new ReduceDriver<KEYIN, VALUEIN, KEYOUT, VALUEOUT>(reducer);
>     }
>
> }
>
> I can now write :
>     private MapDriver<Text, Text, Text, Text> mapDriver = MRunit.drive(new
> Mapper<Text, Text, Text, Text>());
>
> which is clearer for me. And the best part is that I only need to care
> about one ''verb' : MRUnit.drive(...). Whether it is Mapper/Reducer or
> old/new API, it works, thanks to java checking the type of the argument.
>
> I would like to have your feedbacks about it and to know if ideally it
> could be added to the next version so that I won't have to keep that glue
> code.
>
> Regards
>
> Bertrand
>