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

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

Introduction

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

Prototype

public LongWritable(long value) 

Source Link

Usage

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);//from w  w w . j  ava 2 s . co 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. j a va2  s .c  o m*/

    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);/*from   w w w.  jav a  2s . c om*/

    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.eclat.EclatMinerReducerSetCount.java

License:Apache License

@Override
public void reduce(Text key, Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long levelTotal = 0;
    for (LongWritable lw : values) {
        levelTotal += lw.get();/*from w  w w . j  av  a2  s . c o  m*/
    }
    total += levelTotal;
    context.write(key, new LongWritable(levelTotal));
}

From source file:be.uantwerpen.adrem.eclat.EclatMinerReducerSetCount.java

License:Apache License

@Override
public void cleanup(Context context) throws IOException, InterruptedException {
    System.out.println("Total: " + total);
    context.write(new Text("Total"), new LongWritable(total));
}

From source file:be.uantwerpen.adrem.eclat.util.ItemsetLengthCountReporter.java

License:Apache License

@Override
public void close() {
    try {/*w w  w  .  j  a  v  a 2s.com*/
        for (Entry<Integer, MutableLong> entry : counts.entrySet()) {
            context.write(new Text("" + entry.getKey()), new LongWritable(entry.getValue().longValue()));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:ca.nlap.giraphsociallayout.ConnectedComponentsComputation.java

License:Apache License

/**
 * Propagates the smallest vertex id to all neighbors. Will always choose to
 * halt and only reactivate if a smaller id has been sent to it.
 *
 * @param vertex Vertex//from  w  ww. jav a 2s . c o m
 * @param messages Iterator of messages from the previous superstep.
 * @throws IOException
 */
@Override
public void compute(Vertex<LongWritable, LongWritable, NullWritable> vertex, Iterable<LongWritable> messages)
        throws IOException {
    long currentComponent = vertex.getValue().get();

    // First superstep is special, because we can simply look at the neighbors
    if (getSuperstep() == 0) {
        for (Edge<LongWritable, NullWritable> edge : vertex.getEdges()) {
            long neighbor = edge.getTargetVertexId().get();
            if (neighbor < currentComponent) {
                currentComponent = neighbor;
            }
        }
        // Only need to send value if it is not the own id
        if (currentComponent != vertex.getValue().get()) {
            vertex.setValue(new LongWritable(currentComponent));
            for (Edge<LongWritable, NullWritable> edge : vertex.getEdges()) {
                LongWritable neighbor = edge.getTargetVertexId();
                if (neighbor.get() > currentComponent) {
                    sendMessage(neighbor, vertex.getValue());
                }
            }
        }

        vertex.voteToHalt();
        return;
    }

    boolean changed = false;
    // did we get a smaller id ?
    for (LongWritable message : messages) {
        long candidateComponent = message.get();
        if (candidateComponent < currentComponent) {
            currentComponent = candidateComponent;
            changed = true;
        }
    }

    // propagate new component id to the neighbors
    if (changed) {
        vertex.setValue(new LongWritable(currentComponent));
        sendMessageToAllEdges(vertex, vertex.getValue());
    }
    vertex.voteToHalt();
}

From source file:cascading.hive.ORCFile.java

License:Apache License

private void tuple2Struct(Tuple tuple, OrcStruct struct) {
    Object value = null;/*from   w w  w .  j  a v  a  2s .  co  m*/
    for (int i = 0; i < types.length; i++) {
        switch (typeMapping.get(types[i].toLowerCase())) {
        case INT:
            value = tuple.getObject(i) == null ? null : new IntWritable(tuple.getInteger(i));
            break;
        case BOOLEAN:
            value = tuple.getObject(i) == null ? null : new BooleanWritable(tuple.getBoolean(i));
            break;
        case TINYINT:
            value = tuple.getObject(i) == null ? null : new ByteWritable(Byte.valueOf(tuple.getString(i)));
            break;
        case SMALLINT:
            value = tuple.getObject(i) == null ? null : new ShortWritable(tuple.getShort(i));
            break;
        case BIGINT:
            value = tuple.getObject(i) == null ? null : new LongWritable(tuple.getLong(i));
            break;
        case FLOAT:
            value = tuple.getObject(i) == null ? null : new FloatWritable(tuple.getFloat(i));
            break;
        case DOUBLE:
            value = tuple.getObject(i) == null ? null : new DoubleWritable(tuple.getDouble(i));
            break;
        case BIGDECIMAL:
            value = tuple.getObject(i) == null ? null
                    : new HiveDecimalWritable(HiveDecimal.create((new BigDecimal(tuple.getString(i)))));
            break;
        case STRING:
        default:
            value = tuple.getObject(i) == null ? null : new Text(tuple.getString(i));
        }
        struct.setFieldValue(i, value);
    }
}

From source file:co.cask.cdap.data.stream.StreamInputFormatTest.java

License:Apache License

@Test
public void testIdentityStreamEventDecoder() {
    ImmutableMap.Builder<String, String> headers = ImmutableMap.builder();
    headers.put("key1", "value1");
    headers.put("key2", "value2");
    ByteBuffer buffer = Charsets.UTF_8.encode("testdata");
    StreamEvent event = new StreamEvent(headers.build(), buffer, System.currentTimeMillis());
    StreamEventDecoder<LongWritable, StreamEvent> decoder = new IdentityStreamEventDecoder();
    StreamEventDecoder.DecodeResult<LongWritable, StreamEvent> result = new StreamEventDecoder.DecodeResult<>();
    result = decoder.decode(event, result);
    Assert.assertEquals(new LongWritable(event.getTimestamp()), result.getKey());
    Assert.assertEquals(event, result.getValue());
}

From source file:co.cask.hydrator.plugin.batchSource.KafkaKey.java

License:Apache License

public void setMessageSize(long messageSize) {
    Text key = new Text("message.size");
    put(key, new LongWritable(messageSize));
}