Example usage for org.apache.hadoop.io Text Text

List of usage examples for org.apache.hadoop.io Text Text

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text Text.

Prototype

public Text(byte[] utf8) 

Source Link

Document

Construct from a byte array.

Usage

From source file:be.uantwerpen.adrem.bigfim.AprioriPhaseReducerTest.java

License:Apache License

@Test
public void numberOfPGCounter_Multiple_Groups()
        throws IOException, InterruptedException, NoSuchFieldException, IllegalAccessException {
    AprioriPhaseReducer.Context ctx = createMock(Reducer.Context.class);
    Counter pgCounter = createMockCounter(3);

    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRPREFIXGROUPS)).andReturn(pgCounter).anyTimes();
    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRLARGEPREFIXGROUPS))
            .andReturn(new Counters().findCounter(COUNTER_GROUPNAME, COUNTER_NRLARGEPREFIXGROUPS)).anyTimes();

    EasyMock.replay(ctx, pgCounter);/*from   ww  w  . j  ava  2s . co m*/

    AprioriPhaseReducer reducer = createAprioriPhaseReducer(1, createMultipleOutputsTwoPrefix(1));
    for (String prefix : new String[] { "1", "2", "4" }) {
        reducer.reduce(new Text(prefix), createReducerInputTwoPrefix(prefix), ctx);
    }
    reducer.cleanup(ctx);

    EasyMock.verify(ctx, pgCounter);
}

From source file:be.uantwerpen.adrem.bigfim.AprioriPhaseReducerTest.java

License:Apache License

@Test
public void numberOfLargePGCounter_One_Group_Not_Large()
        throws IOException, InterruptedException, NoSuchFieldException, IllegalAccessException {
    AprioriPhaseReducer.Context ctx = createMock(Reducer.Context.class);
    Counter pgCounter = createMockCounter(0);

    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRPREFIXGROUPS))
            .andReturn(new Counters().findCounter(COUNTER_GROUPNAME, COUNTER_NRPREFIXGROUPS)).anyTimes();
    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRLARGEPREFIXGROUPS)).andReturn(pgCounter)
            .anyTimes();/*from w ww .  j av a  2  s  .  com*/

    EasyMock.replay(ctx, pgCounter);

    int tmp = ComputeTidListReducer.MAX_NUMBER_OF_TIDS;
    ComputeTidListReducer.MAX_NUMBER_OF_TIDS = 50;

    AprioriPhaseReducer reducer = createAprioriPhaseReducer(1, createMultipleOutputsOnePrefix(1));
    reducer.reduce(new Text(""), createReducerInput(), ctx);
    reducer.cleanup(ctx);

    EasyMock.verify(ctx, pgCounter);

    ComputeTidListReducer.MAX_NUMBER_OF_TIDS = tmp;
}

From source file:be.uantwerpen.adrem.bigfim.AprioriPhaseReducerTest.java

License:Apache License

@Test
public void numberOfLargePGCounter_One_Group_Is_Large()
        throws IOException, InterruptedException, NoSuchFieldException, IllegalAccessException {
    AprioriPhaseReducer.Context ctx = createMock(Reducer.Context.class);
    Counter pgCounter = createMockCounter(1);

    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRPREFIXGROUPS))
            .andReturn(new Counters().findCounter(COUNTER_GROUPNAME, COUNTER_NRPREFIXGROUPS)).anyTimes();
    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRLARGEPREFIXGROUPS)).andReturn(pgCounter)
            .anyTimes();/*from  www  . j av a2  s  . c o  m*/

    EasyMock.replay(ctx, pgCounter);

    int tmp = ComputeTidListReducer.MAX_NUMBER_OF_TIDS;
    ComputeTidListReducer.MAX_NUMBER_OF_TIDS = 10;

    AprioriPhaseReducer reducer = createAprioriPhaseReducer(1, createMultipleOutputsOnePrefix(1));
    reducer.reduce(new Text(""), createReducerInput(), ctx);
    reducer.cleanup(ctx);

    EasyMock.verify(ctx, pgCounter);

    ComputeTidListReducer.MAX_NUMBER_OF_TIDS = tmp;
}

From source file:be.uantwerpen.adrem.bigfim.AprioriPhaseReducerTest.java

License:Apache License

@Test
public void numberOfLargePGCounter_Multiple_Groups()
        throws IOException, InterruptedException, NoSuchFieldException, IllegalAccessException {
    AprioriPhaseReducer.Context ctx = createMock(Reducer.Context.class);
    Counter pgCounter = createMockCounter(2);

    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRPREFIXGROUPS))
            .andReturn(new Counters().findCounter(COUNTER_GROUPNAME, COUNTER_NRPREFIXGROUPS)).anyTimes();
    EasyMock.expect(ctx.getCounter(COUNTER_GROUPNAME, COUNTER_NRLARGEPREFIXGROUPS)).andReturn(pgCounter)
            .anyTimes();//from   ww  w. j  av  a 2s  .  c o  m

    EasyMock.replay(ctx, pgCounter);

    int tmp = ComputeTidListReducer.MAX_NUMBER_OF_TIDS;
    ComputeTidListReducer.MAX_NUMBER_OF_TIDS = 20;

    AprioriPhaseReducer reducer = createAprioriPhaseReducer(1, createMultipleOutputsTwoPrefix(1));
    for (String prefix : new String[] { "1", "2", "4" }) {
        reducer.reduce(new Text(prefix), createReducerInputTwoPrefix(prefix), ctx);
    }
    reducer.cleanup(ctx);

    EasyMock.verify(ctx, pgCounter);

    ComputeTidListReducer.MAX_NUMBER_OF_TIDS = tmp;
}

From source file:be.uantwerpen.adrem.bigfim.ComputeTidListMapper.java

License:Apache License

private void doRecursiveReport(Context context, StringBuilder builder, int depth, ItemSetTrie trie)
        throws IOException, InterruptedException {
    int length = builder.length();
    for (ItemSetTrie recTrie : trie.children.values()) {
        if (recTrie != null) {
            if (depth + 1 == phase) {
                List<Integer> tids = ((ItemSetTrie.TidListItemsetTrie) recTrie).tids;
                if (tids.isEmpty()) {
                    continue;
                }//from  w ww  .j  ava 2 s .  co  m
                Text key = new Text(builder.substring(0, Math.max(0, builder.length() - 1)));
                IntWritable[] iw = createIntWritableWithIdSet(tids.size());
                int i1 = 1;
                iw[i1++] = new IntWritable(recTrie.id);
                for (int tid : tids) {
                    iw[i1++] = new IntWritable(tid);
                }
                iaw.set(iw);
                context.write(key, iaw);
                tids.clear();
            } else {
                builder.append(recTrie.id + " ");
                doRecursiveReport(context, builder, depth + 1, recTrie);
            }
        }
        builder.setLength(length);
    }
}

From source file:be.uantwerpen.adrem.bigfim.ComputeTidListMapperTest.java

License:Apache License

@Test
public void phase_1_With_Input() throws Exception {
    ComputeTidListMapper.Context ctx = createMock(Mapper.Context.class);

    ctx.write(new Text(""), newIAW(-1, 1, 0, 2, 3, 5, 7));
    ctx.write(new Text(""), newIAW(-1, 2, 0, 1, 6));
    ctx.write(new Text(""), newIAW(-1, 3, 0, 1, 2, 4, 5, 7));
    ctx.write(new Text(""), newIAW(-1, 4, 0, 1, 4, 5, 7));
    ctx.write(new Text(""), newIAW(-1, 5, 2, 4, 5, 6));

    EasyMock.replay(ctx);/*from w w  w.java  2  s . c  o  m*/

    ComputeTidListMapper mapper = new ComputeTidListMapper();
    setField(mapper, "delimiter", " ");

    for (int i = 0; i < data.length; i++) {
        mapper.map(new LongWritable(i), new Text(data[i]), ctx);
    }

    mapper.cleanup(ctx);

    EasyMock.verify(ctx);
}

From source file:be.uantwerpen.adrem.bigfim.ComputeTidListMapperTest.java

License:Apache License

@Test
public void phase_2_With_Input() throws Exception {
    ComputeTidListMapper.Context ctx = createMock(Mapper.Context.class);

    ctx.write(new Text("1"), newIAW(-1, 2, 0));
    ctx.write(new Text("1"), newIAW(-1, 3, 0, 2, 5, 7));
    ctx.write(new Text("1"), newIAW(-1, 4, 0, 5, 7));
    ctx.write(new Text("2"), newIAW(-1, 3, 0, 1));
    ctx.write(new Text("2"), newIAW(-1, 5, 6));
    ctx.write(new Text("3"), newIAW(-1, 4, 0, 1, 4, 5, 7));
    ctx.write(new Text("4"), newIAW(-1, 5, 4, 5));

    EasyMock.replay(ctx);/*  www  . ja  v  a2 s  .  c o  m*/

    ComputeTidListMapper mapper = createMapper(2, create_Count_Trie_Not_Empty());

    for (int i = 0; i < data.length; i++) {
        mapper.map(new LongWritable(i), new Text(data[i]), ctx);
    }

    mapper.cleanup(ctx);

    EasyMock.verify(ctx);
}

From source file:be.uantwerpen.adrem.bigfim.ComputeTidListMapperTest.java

License:Apache License

@Test
public void phase_2_With_Input_2() throws Exception {
    ComputeTidListMapper.Context ctx = createMock(Mapper.Context.class);

    EasyMock.replay(ctx);/*from w w w.ja v  a  2s .com*/

    ComputeTidListMapper mapper = createMapper(2, create_Count_Trie_Not_Empty_2());

    for (int i = 0; i < data2.length; i++) {
        mapper.map(new LongWritable(i), new Text(data2[i]), ctx);
    }

    mapper.cleanup(ctx);

    EasyMock.verify(ctx);
}

From source file:be.uantwerpen.adrem.bigfim.ComputeTidListMapperTest.java

License:Apache License

@Test
public void phase_2_With_Input_Empty_Count_Trie() throws Exception {
    ComputeTidListMapper.Context ctx = createMock(Mapper.Context.class);

    EasyMock.replay(ctx);/* w  w  w .  j a va 2 s .  c  o  m*/

    ComputeTidListMapper mapper = createMapper(2, new ItemSetTrie.TidListItemsetTrie(-1));

    for (int i = 0; i < data.length; i++) {
        mapper.map(new LongWritable(i), new Text(data[i]), ctx);
    }

    mapper.cleanup(ctx);

    EasyMock.verify(ctx);
}

From source file:be.uantwerpen.adrem.bigfim.ComputeTidListReducerTest.java

License:Apache License

@Test
public void One_PG_One_Item() throws Exception {
    MultipleOutputs<IntArrayWritable, IntMatrixWritable> mos = createMock(MultipleOutputs.class);
    mos.write(newIAW(1), EmptyImw, "pg/bucket-0");
    mos.write(newIAW(0), new IntMatrixWritable(newIAW(0, 1, 2, 4, 7, 9), newIAW(0, 1, 2, 3, 5, 6, 8)),
            "pg/bucket-0");
    mos.write(EmptyIaw, EmptyImw, "pg/bucket-0");
    mos.close();/* ww w  .  j  a  v a 2 s . c  o m*/

    Reducer.Context ctx = createMock(Reducer.Context.class);
    EasyMock.expect(ctx.getConfiguration()).andReturn(createConfiguration()).anyTimes();
    EasyMock.expect(ctx.getTaskAttemptID()).andReturn(new TaskAttemptID()).anyTimes();

    EasyMock.replay(ctx, mos);

    ComputeTidListReducer reducer = new ComputeTidListReducer();
    reducer.setup(ctx);
    setField(reducer, "mos", mos);

    reducer.reduce(new Text("1"), createTestInput_1Item(), ctx);
    reducer.cleanup(ctx);

    EasyMock.verify(mos);
}