use of org.bson.Document in project mongo-hadoop by mongodb.
the class UDFTest method testObjectIdToSeconds.
@Test
public void testObjectIdToSeconds() throws IOException, ParseException {
PigTest.runScript("/pig/oidtoseconds.pig");
assertEquals(insertedDocuments.size(), OUTPUT_COLLECTION.count());
Iterator<Document> it = insertedDocuments.iterator();
for (Document outputDoc : OUTPUT_COLLECTION.find()) {
int seconds = outputDoc.getInteger("seconds");
int seconds2 = outputDoc.getInteger("seconds2");
int expectedSeconds = it.next().getObjectId("_id").getTimestamp();
assertEquals(expectedSeconds, seconds);
assertEquals(expectedSeconds, seconds2);
}
}
use of org.bson.Document in project mongo-hadoop by mongodb.
the class UDFTest method testUDFsSchemaless.
@Test
public void testUDFsSchemaless() throws IOException, ParseException {
// Test that one of our UDFs can work without any schemas being
// specified. This mostly tests that BSONStorage can infer the type
// correctly.
PigTest.runScript("/pig/udfschemaless.pig");
assertEquals(insertedDocuments.size(), OUTPUT_COLLECTION.count());
Iterator<Document> it = insertedDocuments.iterator();
for (Document doc : OUTPUT_COLLECTION.find()) {
// We don't know what Pig will call the fields that aren't "_id".
ObjectId expectedId = it.next().getObjectId("_id");
for (Map.Entry<String, Object> entry : doc.entrySet()) {
// interested in.
if ("_id".equals(entry.getKey())) {
continue;
}
assertEquals(expectedId, entry.getValue());
}
}
}
use of org.bson.Document in project mongo-hadoop by mongodb.
the class TablePropertiesTest method setUp.
@Before
public void setUp() {
MongoClientURI clientURI = new MongoClientURI("mongodb://localhost:27017/mongo_hadoop.tabletest");
MongoClient client = new MongoClient(clientURI);
// Seed some documents into MongoDB.
collection = client.getDatabase(clientURI.getDatabase()).getCollection(clientURI.getCollection());
ArrayList<Document> documents = new ArrayList<Document>(1000);
for (int i = 0; i < 1000; ++i) {
documents.add(new Document("i", i));
}
collection.insertMany(documents);
// Make sure table doesn't exist already.
dropTable("props_file_test");
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class CodeWithScopeCodec method decode.
@Override
public CodeWithScope decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
String code = bsonReader.readJavaScriptWithScope();
Document scope = documentCodec.decode(bsonReader, decoderContext);
return new CodeWithScope(code, scope);
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class GridFSDownloadStreamImpl method checkAndFetchResults.
private void checkAndFetchResults(final int amountRead, final ByteBuffer dst, final SingleResultCallback<Integer> callback) {
if (currentPosition == fileInfo.getLength() || dst.remaining() == 0) {
callback.onResult(amountRead, null);
} else if (hasResultsToProcess()) {
processResults(amountRead, dst, callback);
} else if (cursor == null) {
chunksCollection.find(new Document("files_id", fileInfo.getId()).append("n", new Document("$gte", chunkIndex))).batchSize(batchSize).sort(new Document("n", 1)).batchCursor(new SingleResultCallback<AsyncBatchCursor<Document>>() {
@Override
public void onResult(final AsyncBatchCursor<Document> result, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else {
cursor = result;
checkAndFetchResults(amountRead, dst, callback);
}
}
});
} else {
cursor.next(new SingleResultCallback<List<Document>>() {
@Override
public void onResult(final List<Document> result, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else if (result == null || result.isEmpty()) {
callback.onResult(null, chunkNotFound(chunkIndex));
} else {
resultsQueue.addAll(result);
if (batchSize == 1) {
discardCursor();
}
processResults(amountRead, dst, callback);
}
}
});
}
}
Aggregations