use of org.apache.hadoop.io.SortedMapWritable in project hadoop by apache.
the class TypedBytesWritableInput method readSortedMap.
public <K extends WritableComparable<? super K>> SortedMapWritable<K> readSortedMap(SortedMapWritable<K> mw) throws IOException {
if (mw == null) {
mw = new SortedMapWritable<K>();
}
int length = in.readMapHeader();
for (int i = 0; i < length; i++) {
@SuppressWarnings("unchecked") K key = (K) read();
Writable value = read();
mw.put(key, value);
}
return mw;
}
use of org.apache.hadoop.io.SortedMapWritable in project hive by apache.
the class TypedBytesWritableInput method readSortedMap.
public SortedMapWritable readSortedMap(SortedMapWritable mw) throws IOException {
if (mw == null) {
mw = new SortedMapWritable();
}
int length = in.readMapHeader();
for (int i = 0; i < length; i++) {
WritableComparable key = (WritableComparable) read();
Writable value = read();
mw.put(key, value);
}
return mw;
}
use of org.apache.hadoop.io.SortedMapWritable in project mongo-hadoop by mongodb.
the class BSONWritableTest method testToBSON.
@Test
public void testToBSON() {
assertEquals(null, toBSON(null));
assertEquals(null, toBSON(NullWritable.get()));
assertEquals("hello", toBSON(new Text("hello")));
DBObject obj = new BasicDBObject("hello", "world");
assertEquals(obj, toBSON(new BSONWritable(obj)));
final BasicBSONObject bsonResult = new BasicBSONObject("one", 1);
SortedMapWritable smw = new SortedMapWritable();
smw.put(new Text("one"), new IntWritable(1));
assertEquals(bsonResult, toBSON(smw));
MapWritable mw = new MapWritable();
mw.put(new Text("one"), new IntWritable(1));
assertEquals(bsonResult, toBSON(mw));
String[] expectedObjects = new String[] { "one", "two" };
Writable[] writableObjects = new Writable[] { new Text("one"), new Text("two") };
ArrayWritable aw = new ArrayWritable(Text.class, writableObjects);
Object[] actual = (Object[]) toBSON(aw);
assertTrue(Arrays.equals(expectedObjects, actual));
assertEquals(false, toBSON(new BooleanWritable(false)));
byte[] bytes = new byte[] { '0', '1', '2' };
assertEquals(bytes, toBSON(new BytesWritable(bytes)));
byte b = (byte) 'c';
assertEquals(b, toBSON(new ByteWritable(b)));
assertEquals(3.14159, toBSON(new DoubleWritable(3.14159)));
assertEquals(3.14159f, toBSON(new FloatWritable(3.14159f)));
assertEquals(42L, toBSON(new LongWritable(42L)));
assertEquals(42, toBSON(new IntWritable(42)));
// Catchall
assertEquals("hi", toBSON("hi"));
}
Aggregations