use of com.mongodb.hadoop.io.BSONWritable in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testBinary.
@Test
public void testBinary() throws SerDeException {
String columnNames = "b";
String columnTypes = "binary";
byte[] value = new byte[2];
value[0] = 'A';
value[1] = '1';
BSONSerDe serde = new BSONSerDe();
Object result = helpDeserialize(serde, columnNames, columnTypes, value);
assertThat(value, equalTo(result));
ObjectInspector innerInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(byte[].class);
BasicBSONObject bObject = new BasicBSONObject();
Object serialized = helpSerialize(columnNames, innerInspector, bObject, value, serde);
assertThat(new BSONWritable(bObject), equalTo(serialized));
}
use of com.mongodb.hadoop.io.BSONWritable in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testObjectID.
@Test
public void testObjectID() throws SerDeException {
String columnNames = "o";
String columnTypes = "struct<oid:string,bsontype:int>";
ObjectId value = new ObjectId();
ArrayList<Object> returned = new ArrayList<Object>(2);
returned.add(value.toString());
returned.add(8);
BSONSerDe serde = new BSONSerDe();
Object result = helpDeserialize(serde, columnNames, columnTypes, value);
assertThat(returned, equalTo(result));
// Since objectid is currently taken to be a string
ObjectInspector innerInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(String.class);
BasicBSONObject bObject = new BasicBSONObject();
Object serialized = helpSerialize(columnNames, innerInspector, bObject, value.toString(), serde);
assertThat(new BSONWritable(bObject), equalTo(serialized));
}
use of com.mongodb.hadoop.io.BSONWritable in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testList.
@Test
public void testList() throws SerDeException {
String columnNames = "a";
String columnTypes = "array<string>";
String inner = "inside";
ArrayList<String> value = new ArrayList<String>();
value.add(inner);
BasicBSONList b = new BasicBSONList();
b.add(inner);
BSONSerDe serde = new BSONSerDe();
Object result = helpDeserialize(serde, columnNames, columnTypes, b);
assertThat(value.toArray(), equalTo(result));
// Since objectid is currently taken to be a string
ObjectInspector innerInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(String.class);
ListObjectInspector listInspector = ObjectInspectorFactory.getStandardListObjectInspector(innerInspector);
BasicBSONObject bObject = new BasicBSONObject();
Object serialized = helpSerialize(columnNames, listInspector, bObject, value, serde);
assertThat(new BSONWritable(bObject), equalTo(serialized));
}
use of com.mongodb.hadoop.io.BSONWritable in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testDouble.
@Test
public void testDouble() throws SerDeException {
String columnNames = "doub";
String columnTypes = "double";
Double value = 1.1D;
BSONSerDe serde = new BSONSerDe();
Object result = helpDeserialize(serde, columnNames, columnTypes, value);
assertThat(value, equalTo(result));
ObjectInspector innerInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(Double.class);
BasicBSONObject bObject = new BasicBSONObject();
Object serialized = helpSerialize(columnNames, innerInspector, bObject, value, serde);
assertThat(new BSONWritable(bObject), equalTo(serialized));
}
use of com.mongodb.hadoop.io.BSONWritable in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testNumericCasts.
@Test
public void testNumericCasts() throws SerDeException {
BSONSerDe serde = new BSONSerDe();
String colName = "cast";
Number[] nums = { 42.0D, 42, (short) 42, 42.0f, 42L };
Class[] numericClasses = { Double.class, Integer.class, Short.class, Float.class, Long.class };
for (Number num : nums) {
// Double
Object result = helpDeserialize(serde, colName, "double", num);
assertThat(num.doubleValue(), equalTo(result));
// Int
result = helpDeserialize(serde, colName, "int", num);
assertThat(num.intValue(), equalTo(result));
// Short
result = helpDeserialize(serde, colName, "smallint", num);
assertThat(num.shortValue(), equalTo(result));
// Float
result = helpDeserialize(serde, colName, "float", num);
assertThat(num.floatValue(), equalTo(result));
// Long
result = helpDeserialize(serde, colName, "bigint", num);
assertThat(num.longValue(), equalTo(result));
for (Class klass : numericClasses) {
ObjectInspector oi = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(klass);
BasicBSONObject obj = new BasicBSONObject();
Object serialized = helpSerialize(colName, oi, obj, num, serde);
assertThat(new BSONWritable(obj), equalTo(serialized));
}
}
}
Aggregations