Example usage for org.apache.hadoop.io ByteWritable get

List of usage examples for org.apache.hadoop.io ByteWritable get

Introduction

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

Prototype

public byte get() 

Source Link

Document

Return the value of this ByteWritable.

Usage

From source file:com.axiomine.largecollections.kryo.serializers.ByteWritableSerializer.java

License:Apache License

public void write(Kryo kryo, Output output, ByteWritable object) {
    output.writeByte(object.get());
}

From source file:com.csiro.hadoop.WritableTest.java

public static void main(String[] args) {
    System.out.println("*** Primitive Writable ***");

    BooleanWritable bool1 = new BooleanWritable(true);
    ByteWritable byte1 = new ByteWritable((byte) 3);
    System.out.printf("Boolean:%s Byte:%d\n", bool1, byte1.get());

    IntWritable int1 = new IntWritable(5);
    IntWritable int2 = new IntWritable(17);
    System.out.printf("I1:%d I2:%d\n", int1.get(), int2.get());

    int1.set(int2.get());
    System.out.printf("I1:%d I2:%d\n", int1.get(), int2.get());

    Integer int3 = new Integer(23);
    int1.set(int3);
    System.out.printf("I1:%d I2:%d\n", int1.get(), int2.get());

    System.out.println("*** Array Writable ***");

    ArrayWritable a = new ArrayWritable(IntWritable.class);
    a.set(new IntWritable[] { new IntWritable(1), new IntWritable(3), new IntWritable(5) });

    IntWritable[] values = (IntWritable[]) a.get();
    for (IntWritable i : values) {
        System.out.println(i);//  w w w  .  j  a va 2 s .c  om
    }

    IntArrayWritable ia = new IntArrayWritable();
    ia.set(new IntWritable[] { new IntWritable(1), new IntWritable(3), new IntWritable(5) });

    IntWritable[] ivalues = (IntWritable[]) ia.get();

    ia.set((new LongWritable[] { new LongWritable(10001) }));

    System.out.println("*** Map Writables ***");

    MapWritable m = new MapWritable();
    IntWritable key1 = new IntWritable(5);
    NullWritable value1 = NullWritable.get();

    m.put(key1, value1);
    System.out.println(m.containsKey(key1));
    System.out.println(m.get(key1));
    m.put(new LongWritable(100000000), key1);
    Set<Writable> keys = m.keySet();

    for (Writable k : keys)
        System.out.println(k.getClass());

}

From source file:com.ibm.bi.dml.runtime.matrix.mapred.CSVReblockMapper.java

License:Open Source License

@Override
@SuppressWarnings("deprecation")
public void configure(JobConf job) {
    super.configure(job);
    //get the number colums per block

    //load the offset mapping
    byte matrixIndex = representativeMatrixes.get(0);
    try {/*from   w w w.jav  a2s  .  c o  m*/
        FileSystem fs = FileSystem.get(job);
        Path thisPath = new Path(job.get("map.input.file")).makeQualified(fs);
        String filename = thisPath.toString();
        Path headerPath = new Path(job.getStrings(CSVReblockMR.SMALLEST_FILE_NAME_PER_INPUT)[matrixIndex])
                .makeQualified(fs);
        if (headerPath.toString().equals(filename))
            headerFile = true;

        ByteWritable key = new ByteWritable();
        OffsetCount value = new OffsetCount();
        Path p = new Path(job.get(CSVReblockMR.ROWID_FILE_NAME));
        SequenceFile.Reader reader = new SequenceFile.Reader(fs, p, job);
        while (reader.next(key, value)) {
            if (key.get() == matrixIndex && filename.equals(value.filename))
                offsetMap.put(value.fileOffset, value.count);
        }
        reader.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    CSVReblockInstruction ins = csv_reblock_instructions.get(0).get(0);
    _delim = ins.delim;
    ignoreFirstLine = ins.hasHeader;

    idxRow = new IndexedBlockRow();
    int maxBclen = 0;

    for (ArrayList<CSVReblockInstruction> insv : csv_reblock_instructions)
        for (CSVReblockInstruction in : insv) {
            if (maxBclen < in.bclen)
                maxBclen = in.bclen;
        }

    //always dense since common csv usecase
    idxRow.getRow().data.reset(1, maxBclen, false);
}

From source file:edu.uci.ics.pregelix.example.ReachabilityVertex.java

License:Apache License

@Override
public void compute(Iterator<ByteWritable> msgIterator) {
    if (sourceId < 0) {
        sourceId = getContext().getConfiguration().getLong(SOURCE_ID, SOURCE_ID_DEFAULT);
    }//from ww  w . j a v a  2  s. c  o m
    if (getSuperstep() == 1) {
        boolean isSource = isSource(getVertexId());
        if (isSource) {
            tmpVertexValue.set((byte) 1);
            setVertexValue(tmpVertexValue);
        }
        boolean isDest = isDest(getVertexId());
        if (isDest) {
            tmpVertexValue.set((byte) 2);
            setVertexValue(tmpVertexValue);
        }
        if (isSource && isDest) {
            signalTerminate();
            return;
        }
        if (isSource || isDest) {
            sendOutMsgs();
        } else {
            tmpVertexValue.set((byte) 0);
            setVertexValue(tmpVertexValue);
        }
    } else {
        while (msgIterator.hasNext()) {
            ByteWritable msg = msgIterator.next();
            int msgValue = msg.get();
            if (msgValue < 3) {
                int state = getVertexValue().get();
                int newState = state | msgValue;
                boolean changed = state == newState ? false : true;
                if (changed) {
                    tmpVertexValue.set((byte) newState);
                    setVertexValue(tmpVertexValue);
                    if (newState < 3) {
                        sendOutMsgs();
                    } else {
                        signalTerminate();
                    }
                }
            } else {
                signalTerminate();
            }
        }
    }
    voteToHalt();
}

From source file:io.apigee.lembos.mapreduce.converters.input.ByteWritableConverter.java

License:Apache License

/**
 * Takes in a {@link ByteWritable} and returns a {@link byte}.
 *
 * @param scope the JavaScript scope/*from  www .  ja v a2s  .  c  om*/
 * @param writable the value to convert
 *
 * @return the JavaScript array equivalent
 */
@Override
public Object toJavaScript(final Scriptable scope, final ByteWritable writable) {
    return writable.get();
}

From source file:org.apache.giraph.mapping.LongByteMappingStore.java

License:Apache License

@Override
public void addEntry(LongWritable vertexId, ByteWritable target) {
    long key = vertexId.get() >>> lowerOrder;
    byte[] bytes = concurrentIdToBytes.get(key);
    if (bytes == null) {
        byte[] newBytes = new byte[lower];
        Arrays.fill(newBytes, (byte) -1);
        bytes = concurrentIdToBytes.putIfAbsent(key, newBytes);
        if (bytes == null) {
            bytes = newBytes;/*  w ww .j a  v a2 s  .c o  m*/
        }
    }
    bytes[(int) (vertexId.get() & lowerBitMask)] = target.get();
    numEntries.getAndIncrement(); // increment count
}

From source file:org.apache.giraph.types.ByteWritableToByteUnwrapper.java

License:Apache License

@Override
public Byte unwrap(ByteWritable writableValue) {
    return writableValue.get();
}

From source file:org.apache.giraph.types.ByteWritableToIntUnwrapper.java

License:Apache License

@Override
public Integer unwrap(ByteWritable writableValue) {
    return (int) writableValue.get();
}

From source file:org.apache.giraph.types.ByteWritableToLongUnwrapper.java

License:Apache License

@Override
public Long unwrap(ByteWritable writableValue) {
    return (long) writableValue.get();
}

From source file:org.apache.giraph.types.ByteWritableToShortUnwrapper.java

License:Apache License

@Override
public Short unwrap(ByteWritable writableValue) {
    return (short) writableValue.get();
}