use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoStorageOptions method parseIndex.
private static void parseIndex(final Matcher match, final Index i) {
// Build our index object
i.index = new BasicDBObject();
String index = match.group(1);
Matcher indexKeys = KEY_VALUE_REGEX.matcher(index);
while (indexKeys.find()) {
i.index.put(indexKeys.group(1), Integer.parseInt(indexKeys.group(2)));
}
// Build our options object
i.options = new BasicDBObject();
String options = match.group(2);
Matcher optionsKeys = KEY_VALUE_REGEX.matcher(options);
while (optionsKeys.find()) {
String value = optionsKeys.group(2);
i.options.put(optionsKeys.group(1), Boolean.parseBoolean(value));
}
if (!i.options.containsField("sparse")) {
i.options.put("sparse", false);
}
if (!i.options.containsField("unique")) {
i.options.put("unique", false);
}
if (!i.options.containsField("dropDups")) {
i.options.put("dropDups", false);
}
if (!i.options.containsField("background")) {
i.options.put("background", false);
}
}
use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoLoaderTest method testBinaryNoSchema.
@Test
@SuppressWarnings("unchecked")
public void testBinaryNoSchema() throws IOException {
byte[] data = new byte[] { 1, 2, 3 };
BasicDBObject obj = new BasicDBObject("bytes", new Binary(data));
MongoRecordReader rr = mock(MongoRecordReader.class);
when(rr.nextKeyValue()).thenReturn(true);
when(rr.getCurrentValue()).thenReturn(obj);
// No explicit schema.
MongoLoader ml = new MongoLoader();
ml.prepareToRead(rr, null);
Tuple result = ml.getNext();
// Tuple just contains a Map.
Map<String, Object> tupleContents;
tupleContents = (Map<String, Object>) result.get(0);
// Map contains DataByteArray with binary data.
assertArrayEquals(data, ((DataByteArray) tupleContents.get("bytes")).get());
}
use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoLoaderTest method testSimpleTupleIncorrectFieldType.
@Test
public void testSimpleTupleIncorrectFieldType() throws IOException {
String userSchema = "t:tuple(t1:chararray, t2:float)";
Object val = new BasicDBObject().append("t1", "t1_value").append("t2", "t2_value");
MongoLoader ml = new MongoLoader(userSchema);
Object result = BSONLoader.readField(val, ml.getFields()[0]);
Tuple t = (Tuple) result;
assertEquals(2, t.size());
assertEquals("t1_value", t.get(0));
assertNull(t.get(1));
}
use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoLoaderTest method testSimpleTuple.
@Test
public void testSimpleTuple() throws IOException {
String userSchema = "t:tuple(t1:chararray, t2:chararray)";
Object val = new BasicDBObject().append("t1", "t1_value").append("t2", "t2_value");
MongoLoader ml = new MongoLoader(userSchema);
Object result = BSONLoader.readField(val, ml.getFields()[0]);
Tuple t = (Tuple) result;
assertEquals(2, t.size());
assertEquals("t1_value", t.get(0));
assertEquals("t2_value", t.get(1));
}
use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoLoaderTest method testSimpleBag.
@Test
public void testSimpleBag() throws IOException {
String userSchema = "b:{t:tuple(t1:chararray, t2:chararray)}";
BasicDBList bag = new BasicDBList();
bag.add(new BasicDBObject().append("t1", "t11_value").append("t2", "t12_value"));
bag.add(new BasicDBObject().append("t1", "t21_value").append("t2", "t22_value"));
MongoLoader ml = new MongoLoader(userSchema);
Object result = BSONLoader.readField(bag, ml.getFields()[0]);
DataBag b = (DataBag) result;
Iterator<Tuple> bit = b.iterator();
Tuple firstInnerT = bit.next();
assertEquals(2, firstInnerT.size());
assertEquals("t11_value", firstInnerT.get(0));
assertEquals("t12_value", firstInnerT.get(1));
Tuple secondInnerT = bit.next();
assertEquals(2, secondInnerT.size());
assertEquals("t21_value", secondInnerT.get(0));
assertEquals("t22_value", secondInnerT.get(1));
assertFalse(bit.hasNext());
}
Aggregations