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();
}
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;
}
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));
}
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"));
}
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));
}
Aggregations