use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.
the class TimestampPolicyMongoRyaStatementStore method fetchStatements.
@Override
public Iterator<RyaStatement> fetchStatements() throws FetchStatementException {
final DBObject timeObj = new BasicDBObjectBuilder().add(SimpleMongoDBStorageStrategy.TIMESTAMP, new BasicDBObjectBuilder().add("$gte", timestamp.getTime()).get()).get();
final Cursor cur = db.getCollection(TRIPLES_COLLECTION).find(timeObj).sort(new BasicDBObject(TIMESTAMP, 1));
final List<RyaStatement> statements = new ArrayList<>();
while (cur.hasNext()) {
final RyaStatement statement = adapter.deserializeDBObject(cur.next());
statements.add(statement);
}
return statements.iterator();
}
use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.
the class HiveMongoInputFormatTest method testTranslateConjoinedQuery.
@Test
public void testTranslateConjoinedQuery() {
// i < 50
GenericUDFOPLessThan lt = new GenericUDFOPLessThan();
ExprNodeDesc[] iLt50Children = { new ExprNodeColumnDesc(new SimpleMockColumnInfo("i")), new ExprNodeConstantDesc(50) };
ExprNodeGenericFuncDesc iLt50 = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, lt, Arrays.asList(iLt50Children));
// j > 20
GenericUDFOPGreaterThan gt = new GenericUDFOPGreaterThan();
ExprNodeDesc[] jGt20Children = { new ExprNodeColumnDesc(new SimpleMockColumnInfo("j")), new ExprNodeConstantDesc(20) };
ExprNodeGenericFuncDesc jGt20 = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, gt, Arrays.asList(jGt20Children));
// i < 50 AND j > 20
ExprNodeDesc[] andExprChildren = { iLt50, jGt20 };
ExprNodeGenericFuncDesc expr = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, new GenericUDFOPAnd(), Arrays.asList(andExprChildren));
assertEquals(// {"$and": [{"i": {"$lt": 50}}, {"j": {"$gt": 20}}]}
new BasicDBObjectBuilder().push("mongo_i").add("$lt", 50).pop().push("mongo_j").add("$gt", 20).pop().get(), filterForExpr(expr));
}
use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.
the class HiveMongoInputFormatTest method testProjectionWithColumnMapping.
@Test
public void testProjectionWithColumnMapping() {
DBObject mapping = new BasicDBObjectBuilder().add("i", "mongo_i").add("j", "mongo_j").add("id", "_id").get();
String selectedColumns = "id,i";
JobConf conf = new JobConf();
conf.set(ColumnProjectionUtils.READ_COLUMN_NAMES_CONF_STR, selectedColumns);
conf.set(BSONSerDe.MONGO_COLS, JSON.serialize(mapping));
conf.setBoolean(ColumnProjectionUtils.READ_ALL_COLUMNS, false);
// _id field is implicitly mapped to id field in Hive.
assertEquals(new BasicDBObjectBuilder().add("mongo_i", 1).add("_id", 1).get(), inputFormat.getProjection(conf, colNameMapping));
}
use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.
the class BSONStorage method putNext.
@Override
public void putNext(final Tuple tuple) throws IOException {
try {
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
ResourceFieldSchema[] fields = null;
if (schema != null) {
fields = schema.getFields();
}
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
writeField(builder, fields[i], tuple.get(i));
}
} else {
for (int i = 0; i < tuple.size(); i++) {
writeField(builder, null, tuple.get(i));
}
}
out.write(null, builder.get());
} catch (Exception e) {
throw new IOException("Couldn't convert tuple to bson: ", e);
}
}
use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.
the class MongoInsertStorage method putNext.
@Override
public void putNext(final Tuple tuple) throws IOException {
try {
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
ResourceFieldSchema[] fields = null;
if (schema != null) {
fields = schema.getFields();
}
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
writeField(builder, fields[i], tuple.get(i));
}
} else {
// MongoLoader, for example.
if (tuple.size() != 1) {
throw new IOException("Could not retrieve schema, but tuples did not contain a single item: " + tuple);
}
Object result = BSONStorage.getTypeForBSON(tuple.get(0), null, null);
if (!(result instanceof Map)) {
throw new IOException("Could not retrieve schema, but tuples contained something other than a Map: " + tuple);
}
Map<String, Object> documentMap = (Map<String, Object>) result;
for (Map.Entry<String, Object> entry : documentMap.entrySet()) {
builder.add(entry.getKey(), entry.getValue());
}
}
out.write(null, builder.get());
} catch (Exception e) {
throw new IOException("Couldn't convert tuple to bson: ", e);
}
}
Aggregations