Search in sources :

Example 11 with MongoClientURI

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

the class TestSharded method testMultiMongos.

@Test
public void testMultiMongos() {
    MongoClientURI outputUri = getOutputUri();
    MapReduceJob job = new MapReduceJob(TreasuryYieldXMLConfig.class.getName()).jar(JOBJAR_PATH).param(INPUT_MONGOS_HOSTS, "localhost:27017 localhost:27018").inputUris(getInputUri()).outputUri(outputUri);
    if (isHadoopV1()) {
        job.outputCommitter(MongoOutputCommitter.class);
    }
    job.execute(isRunTestInVm());
    compareResults(getMongos().getDB(outputUri.getDatabase()).getCollection(outputUri.getCollection()), getReference());
}
Also used : MongoClientURI(com.mongodb.MongoClientURI) MapReduceJob(com.mongodb.hadoop.testutils.MapReduceJob) TreasuryYieldXMLConfig(com.mongodb.hadoop.examples.treasury.TreasuryYieldXMLConfig) Test(org.junit.Test)

Example 12 with MongoClientURI

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

the class TestStandalone method collectionSettings.

private JsonNode collectionSettings() {
    ArrayNode settings = new ArrayNode(JsonNodeFactory.instance);
    ObjectNode node = new ObjectNode(JsonNodeFactory.instance);
    node.put(INPUT_URI, getInputUri().toString());
    ObjectNode dow = new ObjectNode(JsonNodeFactory.instance);
    dow.put("dayOfWeek", "FRIDAY");
    node.put("query", dow);
    node.put(MONGO_SPLITTER_CLASS, SingleMongoSplitter.class.getName());
    node.put(SPLITS_USE_RANGEQUERY, true);
    node.put(INPUT_NOTIMEOUT, true);
    settings.add(node);
    MongoClientURI inputUri3 = authCheck(new MongoClientURIBuilder().collection("mongo_hadoop", "yield_historical.in3")).build();
    node = new ObjectNode(JsonNodeFactory.instance);
    node.put(INPUT_URI, inputUri3.toString());
    node.put(SPLITS_USE_RANGEQUERY, true);
    node.put(INPUT_NOTIMEOUT, true);
    settings.add(node);
    return settings;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) MongoClientURIBuilder(com.mongodb.hadoop.util.MongoClientURIBuilder) SingleMongoSplitter(com.mongodb.hadoop.splitter.SingleMongoSplitter) MongoClientURI(com.mongodb.MongoClientURI) ArrayNode(org.codehaus.jackson.node.ArrayNode)

Example 13 with MongoClientURI

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

the class HiveMappingTest method queryBasedHiveTable.

@Test
public void queryBasedHiveTable() throws SQLException {
    String tableName = "filtered";
    DBCollection collection = getCollection(tableName);
    collection.drop();
    dropTable(tableName);
    int size = 1000;
    for (int i = 0; i < size; i++) {
        collection.insert(new BasicDBObject("_id", i).append("intField", i % 10).append("booleanField", i % 2 == 0).append("stringField", "" + (i % 2 == 0)));
    }
    MongoClientURI uri = authCheck(new MongoClientURIBuilder().collection("mongo_hadoop", collection.getName())).build();
    ColumnMapping map = new ColumnMapping().map("id", "_id", "INT").map("ints", "intField", "INT").map("booleans", "booleanField", "BOOLEAN").map("strings", "stringField", "STRING");
    HiveTableBuilder builder = new HiveTableBuilder().mapping(map).name(tableName).uri(uri).tableProperty(MongoConfigUtil.INPUT_QUERY, "{_id : {\"$gte\" : 900 }}");
    execute(builder.toString());
    assertEquals(format("Should find %d items", size), collection.count(), size);
    Results execute = query(format("SELECT * from %s where id=1", tableName));
    assertTrue(execute.size() == 0);
    int expected = size - 900;
    assertEquals(format("Should find only %d items", expected), query("SELECT count(*) as count from " + tableName).iterator().next().get(0), "" + expected);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) MongoClientURIBuilder(com.mongodb.hadoop.util.MongoClientURIBuilder) MongoClientURI(com.mongodb.MongoClientURI) Test(org.junit.Test)

Example 14 with MongoClientURI

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

the class HiveMappingTest method nestedObjects.

@Test
public void nestedObjects() throws SQLException {
    DBCollection collection = getCollection("hive_addresses");
    collection.drop();
    dropTable("hive_addresses");
    collection.insert(user(1, "Jim", "Beam", "Clermont", "KY"));
    collection.insert(user(2, "Don", "Draper", "New York", "NY"));
    collection.insert(user(3, "John", "Elway", "Denver", "CO"));
    MongoClientURI uri = authCheck(new MongoClientURIBuilder().collection("mongo_hadoop", collection.getName())).build();
    ColumnMapping map = new ColumnMapping().map("id", "_id", "INT").map("firstName", "firstName", "STRING").map("lastName", "lastName", "STRING").map("city", "address.city", "STRING").map("state", "address.state", "STRING");
    //, lastName STRING
    execute(format("CREATE TABLE hive_addresses (id INT, firstName STRING, lastName STRING, city STRING, state STRING)\n" + "STORED BY '%s'\n" + "WITH SERDEPROPERTIES('mongo.columns.mapping'='%s')\n" + "TBLPROPERTIES ('mongo.uri'='%s')", MongoStorageHandler.class.getName(), map.toSerDePropertiesString(), uri));
    Results execute = query("SELECT * from hive_addresses");
    assertEquals("KY", execute.getRow(0).get("state"));
    assertEquals("Don", execute.getRow(1).get("firstname"));
    assertEquals("Denver", execute.getRow(2).get("city"));
}
Also used : DBCollection(com.mongodb.DBCollection) MongoClientURIBuilder(com.mongodb.hadoop.util.MongoClientURIBuilder) MongoClientURI(com.mongodb.MongoClientURI) Test(org.junit.Test)

Example 15 with MongoClientURI

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

the class MongoInsertStorage method setStoreLocation.

public void setStoreLocation(final String location, final Job job) throws IOException {
    final Configuration config = job.getConfiguration();
    if (!location.startsWith("mongodb://")) {
        throw new IllegalArgumentException("Invalid URI Format.  URIs must begin with a mongodb:// protocol string.");
    }
    MongoClientURI locURI = new MongoClientURI(location);
    LOG.info(String.format("Store location config: %s; for namespace: %s.%s; hosts: %s", config, locURI.getDatabase(), locURI.getCollection(), locURI.getHosts()));
    MongoConfigUtil.setOutputURI(config, locURI);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MongoClientURI(com.mongodb.MongoClientURI)

Aggregations

MongoClientURI (com.mongodb.MongoClientURI)64 MongoClient (com.mongodb.MongoClient)27 DBCollection (com.mongodb.DBCollection)12 BasicDBObject (com.mongodb.BasicDBObject)9 Test (org.junit.Test)9 MongoClientURIBuilder (com.mongodb.hadoop.util.MongoClientURIBuilder)8 Configuration (org.apache.hadoop.conf.Configuration)8 DBObject (com.mongodb.DBObject)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 InputSplit (org.apache.hadoop.mapreduce.InputSplit)6 DB (com.mongodb.DB)5 MongoDatabase (com.mongodb.client.MongoDatabase)5 MongoInputSplit (com.mongodb.hadoop.input.MongoInputSplit)5 IOException (java.io.IOException)5 MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)5 Document (org.bson.Document)5 OptionParser (joptsimple.OptionParser)4 OptionSet (joptsimple.OptionSet)4 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)4