use of org.apache.hadoop.hive.serde2.SerDeException in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testMap.
@Test
public void testMap() throws SerDeException {
String columnNames = "m";
String columnTypes = "map<string,int>";
BasicBSONObject value = new BasicBSONObject();
String oneKey = "one";
int oneValue = 10;
value.put(oneKey, oneValue);
String twoKey = "two";
int twoValue = 20;
value.put(twoKey, twoValue);
BSONSerDe serde = new BSONSerDe();
Object result = helpDeserialize(serde, columnNames, columnTypes, value);
assertThat(value.toMap(), equalTo(result));
// Since objectid is currently taken to be a string
ObjectInspector keyInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(String.class);
ObjectInspector valueInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(Integer.class);
MapObjectInspector mapInspector = ObjectInspectorFactory.getStandardMapObjectInspector(keyInspector, valueInspector);
BasicBSONObject bObject = new BasicBSONObject();
Object serialized = helpSerialize(columnNames, mapInspector, bObject, value, serde);
assertThat(new BSONWritable(bObject), equalTo(serialized));
}
use of org.apache.hadoop.hive.serde2.SerDeException in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testInt.
@Test
public void testInt() throws SerDeException {
String columnNames = "i";
String columnTypes = "int";
Integer value = 1234;
BSONSerDe serde = new BSONSerDe();
Object result = helpDeserialize(serde, columnNames, columnTypes, value);
assertThat(value, equalTo(result));
ObjectInspector innerInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(Integer.class);
BasicBSONObject bObject = new BasicBSONObject();
Object serialized = helpSerialize(columnNames, innerInspector, bObject, value, serde);
assertThat(new BSONWritable(bObject), equalTo(serialized));
}
use of org.apache.hadoop.hive.serde2.SerDeException in project mongo-hadoop by mongodb.
the class BSONSerDeTest method helpSerialize.
/**
* Given the column names and the object inspector, the serialized object result. Notice how the fieldNames and the fieldInspectors are
* both Lists.
*/
private Object helpSerialize(final String columnNames, final ObjectInspector inner, final BasicBSONObject bObject, final Object value, final BSONSerDe serde) throws SerDeException {
StructObjectInspector oi = createObjectInspector(columnNames, inner);
bObject.put(columnNames, value);
// Structs in Hive are actually arrays/lists of objects
ArrayList<Object> obj = new ArrayList<Object>();
obj.add(value);
return serde.serialize(obj, oi);
}
use of org.apache.hadoop.hive.serde2.SerDeException in project mongo-hadoop by mongodb.
the class BSONSerDeTest method testBoolean.
@Test
public void testBoolean() throws SerDeException {
String columnNames = "bool";
String columnTypes = "boolean";
Boolean value = false;
BSONSerDe serde = new BSONSerDe();
Object result = helpDeserialize(serde, columnNames, columnTypes, value);
assertThat(value, equalTo(result));
ObjectInspector innerInspector = PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(Boolean.class);
BasicBSONObject bObject = new BasicBSONObject();
Object serialized = helpSerialize(columnNames, innerInspector, bObject, value, serde);
assertThat(new BSONWritable(bObject), equalTo(serialized));
}
use of org.apache.hadoop.hive.serde2.SerDeException in project hive by apache.
the class TestPTFRowContainer method setupClass.
@BeforeClass
public static void setupClass() throws SerDeException {
cfg = new Configuration();
serDe = new LazyBinarySerDe();
Properties p = new Properties();
p.setProperty(org.apache.hadoop.hive.serde.serdeConstants.LIST_COLUMNS, COL_NAMES);
p.setProperty(org.apache.hadoop.hive.serde.serdeConstants.LIST_COLUMN_TYPES, COL_TYPES);
SerDeUtils.initializeSerDe(serDe, cfg, p, null);
}
Aggregations