Search in sources :

Example 41 with MongoClientURI

use of com.mongodb.MongoClientURI in project android-uploader by nightscout.

the class MongoUploaderTest method setUp.

@Before
public void setUp() throws Exception {
    mockCollection = mock(DBCollection.class);
    preferences = new TestPreferences();
    mongoUploader = new MongoUploader(preferences, new MongoClientURI("mongodb://localhost"), "collection", "dsCollection");
    mongoUploader.setCollection(mockCollection);
    mongoUploader.setDeviceStatusCollection(mockCollection);
    setUpUpsertCapture();
}
Also used : DBCollection(com.mongodb.DBCollection) MongoClientURI(com.mongodb.MongoClientURI) TestPreferences(com.nightscout.core.preferences.TestPreferences) Before(org.junit.Before)

Example 42 with MongoClientURI

use of com.mongodb.MongoClientURI in project android-uploader by nightscout.

the class Uploader method initializeMongoUploader.

private boolean initializeMongoUploader(Context context, NightscoutPreferences preferences) {
    String dbURI = preferences.getMongoClientUri();
    String collectionName = preferences.getMongoCollection();
    String dsCollectionName = preferences.getMongoDeviceStatusCollection();
    checkNotNull(collectionName);
    checkNotNull(dsCollectionName);
    MongoClientURI uri;
    try {
        uri = new MongoClientURI(dbURI);
    } catch (IllegalArgumentException e) {
        Log.e(LOG_TAG, "Error creating mongo client uri for " + dbURI + ".", e);
        context.sendBroadcast(ToastReceiver.createIntent(context, R.string.unknown_mongo_host));
        return false;
    } catch (NullPointerException e) {
        Log.e(LOG_TAG, "Error creating mongo client uri for null value.", e);
        context.sendBroadcast(ToastReceiver.createIntent(context, R.string.unknown_mongo_host));
        return false;
    }
    uploaders.add(new MongoUploader(preferences, uri, collectionName, dsCollectionName));
    return true;
}
Also used : MongoUploader(com.nightscout.core.upload.MongoUploader) MongoClientURI(com.mongodb.MongoClientURI)

Example 43 with MongoClientURI

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

the class MongoStorage 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);
    final Properties properties = UDFContext.getUDFContext().getUDFProperties(this.getClass(), new String[] { udfContextSignature });
    config.set(PIG_OUTPUT_SCHEMA, properties.getProperty(PIG_OUTPUT_SCHEMA_UDF_CONTEXT));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MongoClientURI(com.mongodb.MongoClientURI) Properties(java.util.Properties)

Example 44 with MongoClientURI

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

the class HiveMappingTest method nestedColumns.

@Test
public void nestedColumns() 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();
    Map<String, String> map = new HashMap<String, String>() {

        {
            put("id", "_id");
            put("firstName", "firstName");
            put("lastName", "lastName");
            put("place.municipality", "address.city");
            put("place.region", "address.state");
        }
    };
    execute(format("CREATE TABLE hive_addresses " + "(id INT, firstName STRING, lastName STRING, " + "place STRUCT<municipality:STRING, region:STRING>)\n" + "STORED BY '%s'\n" + "WITH SERDEPROPERTIES('mongo.columns.mapping'='%s')\n" + "TBLPROPERTIES ('mongo.uri'='%s')", MongoStorageHandler.class.getName(), JSON.serialize(map), uri));
    // Alias inner fields to avoid retrieving entire struct as a String.
    Results execute = query("SELECT place.municipality AS city, place.region AS state, firstname 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) HashMap(java.util.HashMap) MongoClientURI(com.mongodb.MongoClientURI) Test(org.junit.Test)

Example 45 with MongoClientURI

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

the class HiveTest method createMongoBackedTable.

public void createMongoBackedTable(final boolean withSerDeProps) throws SQLException {
    dropTable(MONGO_BACKED_TABLE);
    final MongoClientURI uri = authCheck(new MongoClientURIBuilder().collection("mongo_hadoop", MONGO_COLLECTION)).build();
    execute(format("CREATE TABLE %s %s\n" + "STORED BY '%s'\n" + (withSerDeProps ? format("WITH SERDEPROPERTIES(%s)\n", SERDE_PROPERTIES) : "") + "TBLPROPERTIES ('mongo.uri'='%s')", MONGO_BACKED_TABLE, TEST_SCHEMA, MongoStorageHandler.class.getName(), uri));
}
Also used : MongoClientURIBuilder(com.mongodb.hadoop.util.MongoClientURIBuilder) MongoClientURI(com.mongodb.MongoClientURI)

Aggregations

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