Search in sources :

Example 11 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.

the class MongoStorageTest method testMap.

@Test
public void testMap() throws Exception {
    MongoStorage ms = new MongoStorage();
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    ResourceSchema schema = new ResourceSchema(Utils.getSchemaFromString("m:map[]"));
    Map<String, Object> val = new HashMap<String, Object>();
    val.put("f1", 1);
    val.put("f2", "2");
    ms.writeField(builder, schema.getFields()[0], val);
    DBObject out = builder.get();
    Set<String> outKeySet = out.keySet();
    assertEquals(2, outKeySet.size());
    assertEquals(1, out.get("f1"));
    assertEquals("2", out.get("f2"));
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) ResourceSchema(org.apache.pig.ResourceSchema) HashMap(java.util.HashMap) DBObject(com.mongodb.DBObject) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 12 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.

the class MongoStorage method putNext.

public void putNext(final Tuple tuple) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("writing " + tuple.toString());
    }
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    ResourceFieldSchema[] fields = this.schema.getFields();
    for (int i = 0; i < fields.length; i++) {
        writeField(builder, fields[i], tuple.get(i));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("writing out:" + builder.get().toString());
    }
    // noinspection unchecked
    recordWriter.write(null, builder.get());
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) ResourceFieldSchema(org.apache.pig.ResourceSchema.ResourceFieldSchema)

Example 13 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.

the class ClusterConfigServiceImplTest method getReturnsExistingConfig.

@Test
public void getReturnsExistingConfig() throws Exception {
    DBObject dbObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get();
    @SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    collection.save(dbObject);
    assertThat(collection.count()).isEqualTo(1L);
    CustomConfig customConfig = clusterConfigService.get(CustomConfig.class);
    assertThat(customConfig.text).isEqualTo("TEST");
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 14 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.

the class ClusterConfigServiceImplTest method writeUpdatesExistingClusterConfig.

@Test
public void writeUpdatesExistingClusterConfig() throws Exception {
    CustomConfig customConfig = new CustomConfig();
    customConfig.text = "TEST";
    DBObject seedObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "ORIGINAL")).add("last_updated", TIME.toString()).add("last_updated_by", "NOT ID").get();
    @SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    collection.save(seedObject);
    assertThat(collection.count()).isEqualTo(1L);
    clusterConfigService.write(customConfig);
    assertThat(collection.count()).isEqualTo(1L);
    DBObject dbObject = collection.findOne();
    assertThat((String) dbObject.get("type")).isEqualTo(CustomConfig.class.getCanonicalName());
    assertThat((String) dbObject.get("last_updated_by")).isEqualTo("ID");
    @SuppressWarnings("unchecked") Map<String, Object> payload = (Map<String, Object>) dbObject.get("payload");
    assertThat(payload).containsEntry("text", "TEST");
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) DBObject(com.mongodb.DBObject) Map(java.util.Map) Test(org.junit.Test)

Example 15 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.

the class ClusterConfigServiceImplTest method getWithKeyReturnsExistingConfig.

@Test
public void getWithKeyReturnsExistingConfig() throws Exception {
    DBObject dbObject = new BasicDBObjectBuilder().add("type", "foo").add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get();
    @SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    collection.save(dbObject);
    assertThat(collection.count()).isEqualTo(1L);
    CustomConfig customConfig = clusterConfigService.get("foo", CustomConfig.class);
    assertThat(customConfig).isInstanceOf(CustomConfig.class);
    assertThat(customConfig.text).isEqualTo("TEST");
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)44 DBObject (com.mongodb.DBObject)30 Test (org.junit.Test)21 DBCollection (com.mongodb.DBCollection)18 BasicDBObject (com.mongodb.BasicDBObject)12 ArrayList (java.util.ArrayList)7 BasicDBList (com.mongodb.BasicDBList)6 List (java.util.List)4 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)4 HiveTest (com.mongodb.hadoop.hive.HiveTest)3 IOException (java.io.IOException)3 Map (java.util.Map)3 MongoException (com.mongodb.MongoException)2 Configuration (org.apache.hadoop.conf.Configuration)2 JobConf (org.apache.hadoop.mapred.JobConf)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 ResourceSchema (org.apache.pig.ResourceSchema)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 BasicBSONObject (org.bson.BasicBSONObject)2 GeometryType (org.teiid.core.types.GeometryType)2