Java Code Examples for org.apache.hadoop.io.ArrayWritable#readFields()

The following examples show how to use org.apache.hadoop.io.ArrayWritable#readFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileLatency.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
    areDurationsReady = false;
    fileName = in.readUTF();
    VLongWritable eventCount = new VLongWritable();
    eventCount.readFields(in);
    this.eventCount = eventCount.get();
    ArrayWritable phases = new ArrayWritable(Phase.class);
    phases.readFields(in);
    this.phases = makeList(phases.get());
}
 
Example 2
Source File: TestWritableUtil.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a collection of Strings back from a DataInput.
 *
 * @param input
 * @return collection of strings
 * @throws IOException
 */
public static Collection<String> readCollection(DataInput input) throws IOException {
    ArrayWritable aw = new ArrayWritable(Text.class);
    aw.readFields(input);
    
    Collection<String> coll = new LinkedList<>();
    Writable[] arr = aw.get();
    
    for (int i = 0; i < arr.length; ++i) {
        coll.add(arr[i].toString());
    }
    
    return coll;
}
 
Example 3
Source File: DiscoveryIteratorTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyPath() throws Throwable {
    Connector con = new InMemoryInstance("DiscoveryIteratorTest").getConnector("root", new PasswordToken(""));
    con.tableOperations().create("index");
    writeSample(con.createBatchWriter("index", new BatchWriterConfig().setMaxLatency(0, TimeUnit.SECONDS).setMaxMemory(0).setMaxWriteThreads(1)));
    Scanner s = con.createScanner("index", new Authorizations("FOO"));
    s.addScanIterator(new IteratorSetting(50, DiscoveryIterator.class));
    s.setRange(new Range());
    
    Iterator<Map.Entry<Key,Value>> itr = s.iterator();
    assertTrue(itr.hasNext());
    Map.Entry<Key,Value> e = itr.next();
    assertFalse(itr.hasNext());
    
    Key key = e.getKey();
    assertEquals("term", key.getRow().toString());
    assertEquals("field", key.getColumnFamily().toString());
    // see DiscoveryIterator for why this has a max unsigned char tacked on the end
    assertEquals("20130101\uffff", key.getColumnQualifier().toString());
    
    Value value = e.getValue();
    assertTrue(value.getSize() > 0);
    
    DataInputBuffer in = new DataInputBuffer();
    in.reset(value.get(), value.getSize());
    ArrayWritable valWrapper = new ArrayWritable(DiscoveredThing.class);
    valWrapper.readFields(in);
    Writable[] values = valWrapper.get();
    assertEquals(3, values.length);
    Set<String> types = Sets.newHashSet("t1", "t2", "t3");
    for (int i = 0; i < 3; ++i) {
        DiscoveredThing thing = (DiscoveredThing) values[i];
        assertEquals("term", thing.getTerm());
        assertEquals("field", thing.getField());
        assertTrue(types.remove(thing.getType()));
        assertEquals("20130101", thing.getDate());
        assertEquals("FOO", thing.getColumnVisibility());
        assertEquals(240L, thing.getCount());
    }
}
 
Example 4
Source File: DiscoveryIteratorTest.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Test
public void testReverseIndex() throws Throwable {
    Connector con = new InMemoryInstance("DiscoveryIteratorTest").getConnector("root", new PasswordToken(""));
    con.tableOperations().create("reverseIndex");
    writeSample(con.createBatchWriter("reverseIndex", new BatchWriterConfig().setMaxLatency(0, TimeUnit.SECONDS).setMaxMemory(0).setMaxWriteThreads(1)),
                    true);
    Scanner s = con.createScanner("reverseIndex", new Authorizations("FOO"));
    IteratorSetting setting = new IteratorSetting(50, DiscoveryIterator.class);
    setting.addOption(DiscoveryLogic.REVERSE_INDEX, "true");
    s.addScanIterator(setting);
    s.setRange(new Range());
    
    Iterator<Map.Entry<Key,Value>> itr = s.iterator();
    assertTrue(itr.hasNext());
    Map.Entry<Key,Value> e = itr.next();
    assertFalse(itr.hasNext());
    
    Key key = e.getKey();
    assertEquals("mret", key.getRow().toString());
    assertEquals("field", key.getColumnFamily().toString());
    // see DiscoveryIterator for why this has a max unsigned char tacked on the end
    assertEquals("20130101\uffff", key.getColumnQualifier().toString());
    
    Value value = e.getValue();
    assertTrue(value.getSize() > 0);
    
    DataInputBuffer in = new DataInputBuffer();
    in.reset(value.get(), value.getSize());
    ArrayWritable valWrapper = new ArrayWritable(DiscoveredThing.class);
    valWrapper.readFields(in);
    Writable[] values = valWrapper.get();
    assertEquals(3, values.length);
    Set<String> types = Sets.newHashSet("t1", "t2", "t3");
    for (int i = 0; i < 3; ++i) {
        DiscoveredThing thing = (DiscoveredThing) values[i];
        assertEquals("term", thing.getTerm());
        assertEquals("field", thing.getField());
        assertTrue(types.remove(thing.getType()));
        assertEquals("20130101", thing.getDate());
        assertEquals("FOO", thing.getColumnVisibility());
        assertEquals(240L, thing.getCount());
    }
    
}
 
Example 5
Source File: PriorityQueueWritable.java    From laser with Apache License 2.0 4 votes vote down vote up
public void readFields(DataInput in) throws IOException {
	ArrayWritable arr = new ArrayWritable(IntDoublePairWritable.class);
	arr.readFields(in);
	queue = new PriorityQueue(arr.get());
}