Example usage for org.apache.hadoop.io WritableUtils cloneInto

List of usage examples for org.apache.hadoop.io WritableUtils cloneInto

Introduction

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

Prototype

@Deprecated
public static void cloneInto(Writable dst, Writable src) throws IOException 

Source Link

Document

Make a copy of the writable object using serialization to a buffer

Usage

From source file:crunch.MaxTemperature.java

License:Apache License

@Test
    public void test() throws IOException {
        // vv ArrayWritableTest
        ArrayWritable writable = new ArrayWritable(Text.class);
        // ^^ ArrayWritableTest
        writable.set(new Text[] { new Text("cat"), new Text("dog") });

        TextArrayWritable dest = new TextArrayWritable();
        WritableUtils.cloneInto(dest, writable);
        assertThat(dest.get().length, is(2));
        // TODO: fix cast, also use single assert
        assertThat((Text) dest.get()[0], is(new Text("cat")));
        assertThat((Text) dest.get()[1], is(new Text("dog")));

        Text[] copy = (Text[]) dest.toArray();
        assertThat(copy[0], is(new Text("cat")));
        assertThat(copy[1], is(new Text("dog")));
    }//from   w  w w.  ja v  a2  s . c  om

From source file:crunch.MaxTemperature.java

License:Apache License

@Test
    public void test() throws IOException {
        BinaryOrTextWritable src = new BinaryOrTextWritable();
        src.set(new Text("text"));
        BinaryOrTextWritable dest = new BinaryOrTextWritable();
        WritableUtils.cloneInto(dest, src);
        assertThat((Text) dest.get(), is(new Text("text")));

        src.set(new BytesWritable(new byte[] { 3, 5 }));
        WritableUtils.cloneInto(dest, src);
        assertThat(((BytesWritable) dest.get()).getLength(), is(2)); // TODO proper assert
    }/*from   ww  w .  j a  va2 s .  com*/

From source file:crunch.MaxTemperature.java

License:Apache License

@Test
    public void mapWritable() throws IOException {
        // vv MapWritableTest
        MapWritable src = new MapWritable();
        src.put(new IntWritable(1), new Text("cat"));
        src.put(new VIntWritable(2), new LongWritable(163));

        MapWritable dest = new MapWritable();
        WritableUtils.cloneInto(dest, src);
        assertThat((Text) dest.get(new IntWritable(1)), is(new Text("cat")));
        assertThat((LongWritable) dest.get(new VIntWritable(2)), is(new LongWritable(163)));
        // ^^ MapWritableTest
    }//from  ww w.  ja  v a  2s  .  co  m

From source file:crunch.MaxTemperature.java

License:Apache License

@Test
    public void setWritableEmulation() throws IOException {
        MapWritable src = new MapWritable();
        src.put(new IntWritable(1), NullWritable.get());
        src.put(new IntWritable(2), NullWritable.get());

        MapWritable dest = new MapWritable();
        WritableUtils.cloneInto(dest, src);
        assertThat(dest.containsKey(new IntWritable(1)), is(true));
    }/*from  w  w w .j  a va2 s  . co m*/

From source file:crunch.MaxTemperature.java

License:Apache License

@Test
    public void test() throws IOException {
        ObjectWritable src = new ObjectWritable(Integer.TYPE, 163);
        ObjectWritable dest = new ObjectWritable();
        WritableUtils.cloneInto(dest, src);
        assertThat((Integer) dest.get(), is(163));
    }/*from  w w  w  .  j  a v a 2  s.  com*/

From source file:io.aos.hdfs.ArrayWritableTest.java

License:Apache License

@Test
public void test() throws IOException {
    // vv ArrayWritableTest
    ArrayWritable writable = new ArrayWritable(Text.class);
    // ^^ ArrayWritableTest
    writable.set(new Text[] { new Text("cat"), new Text("dog") });

    TextArrayWritable dest = new TextArrayWritable();
    WritableUtils.cloneInto(dest, writable);
    assertThat(dest.get().length, is(2));
    // TODO: fix cast, also use single assert
    assertThat((Text) dest.get()[0], is(new Text("cat")));
    assertThat((Text) dest.get()[1], is(new Text("dog")));

    Text[] copy = (Text[]) dest.toArray();
    assertThat(copy[0], is(new Text("cat")));
    assertThat(copy[1], is(new Text("dog")));
}

From source file:io.aos.hdfs.MapWritableTest.java

License:Apache License

@Test
public void mapWritable() throws IOException {
    // vv MapWritableTest
    MapWritable src = new MapWritable();
    src.put(new IntWritable(1), new Text("cat"));
    src.put(new VIntWritable(2), new LongWritable(163));

    MapWritable dest = new MapWritable();
    WritableUtils.cloneInto(dest, src);
    assertThat((Text) dest.get(new IntWritable(1)), is(new Text("cat")));
    assertThat((LongWritable) dest.get(new VIntWritable(2)), is(new LongWritable(163)));
    // ^^ MapWritableTest
}

From source file:io.aos.hdfs.MapWritableTest.java

License:Apache License

@Test
public void setWritableEmulation() throws IOException {
    MapWritable src = new MapWritable();
    src.put(new IntWritable(1), NullWritable.get());
    src.put(new IntWritable(2), NullWritable.get());

    MapWritable dest = new MapWritable();
    WritableUtils.cloneInto(dest, src);
    assertThat(dest.containsKey(new IntWritable(1)), is(true));
}

From source file:org.apache.hama.bsp.join.CompositeRecordReader.java

License:Apache License

/**
 * Clone the key at the top of this RR into the given object.
 */
public void key(K key) throws IOException {
    WritableUtils.cloneInto(key, key());
}

From source file:org.apache.hama.bsp.join.JoinRecordReader.java

License:Apache License

/**
 * Emit the next set of key, value pairs as defined by the child RecordReaders
 * and operation associated with this composite RR.
 */// w  w  w  .  j a va 2 s .com
public boolean next(K key, TupleWritable value) throws IOException {
    if (jc.flush(value)) {
        WritableUtils.cloneInto(key, jc.key());
        return true;
    }
    jc.clear();
    K iterkey = createKey();
    final PriorityQueue<ComposableRecordReader<K, ?>> q = getRecordReaderQueue();
    while (!q.isEmpty()) {
        fillJoinCollector(iterkey);
        jc.reset(iterkey);
        if (jc.flush(value)) {
            WritableUtils.cloneInto(key, jc.key());
            return true;
        }
        jc.clear();
    }
    return false;
}