use of org.bson.BsonDocumentWriter in project mongo-java-driver by mongodb.
the class TestCommandListener method getWritableClone.
private BsonDocument getWritableClone(final BsonDocument original) {
BsonDocument clone = new BsonDocument();
BsonDocumentWriter writer = new BsonDocumentWriter(clone);
new BsonDocumentCodec(CODEC_REGISTRY_HACK).encode(writer, original, EncoderContext.builder().build());
return clone;
}
use of org.bson.BsonDocumentWriter in project drill by axbaretto.
the class TestBsonRecordReader method testArrayType.
@Test
public void testArrayType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonWriter bw = new BsonDocumentWriter(bsonDoc);
bw.writeStartDocument();
bw.writeName("arrayKey");
bw.writeStartArray();
bw.writeInt32(1);
bw.writeInt32(2);
bw.writeInt32(3);
bw.writeEndArray();
bw.writeEndDocument();
bw.flush();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
FieldReader reader = mapReader.reader("arrayKey");
assertEquals(3, reader.size());
}
use of org.bson.BsonDocumentWriter in project drill by axbaretto.
the class TestBsonRecordReader method testRecursiveDocuments.
@Test
public void testRecursiveDocuments() throws IOException {
BsonDocument topDoc = new BsonDocument();
final int count = 3;
for (int i = 0; i < count; ++i) {
BsonDocument bsonDoc = new BsonDocument();
BsonWriter bw = new BsonDocumentWriter(bsonDoc);
bw.writeStartDocument();
bw.writeName("k1" + i);
bw.writeString("drillMongo1" + i);
bw.writeName("k2" + i);
bw.writeString("drillMongo2" + i);
bw.writeEndDocument();
bw.flush();
topDoc.append("doc" + i, bsonDoc);
}
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(topDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
for (int i = 0; i < count; ++i) {
SingleMapReaderImpl reader = (SingleMapReaderImpl) mapReader.reader("doc" + i);
assertEquals("drillMongo1" + i, reader.reader("k1" + i).readText().toString());
assertEquals("drillMongo2" + i, reader.reader("k2" + i).readText().toString());
}
}
use of org.bson.BsonDocumentWriter in project drill by apache.
the class TestBsonRecordReader method testArrayOfDocumentType.
@Test
public void testArrayOfDocumentType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonWriter bw = new BsonDocumentWriter(bsonDoc);
bw.writeStartDocument();
bw.writeName("a");
bw.writeString("MongoDB");
bw.writeName("b");
bw.writeStartArray();
bw.writeStartDocument();
bw.writeName("c");
bw.writeInt32(1);
bw.writeEndDocument();
bw.writeEndArray();
bw.writeEndDocument();
bw.flush();
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
FieldReader reader = writer.getMapVector().getReader();
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) reader;
FieldReader reader3 = mapReader.reader("b");
assertEquals("MongoDB", mapReader.reader("a").readText().toString());
}
use of org.bson.BsonDocumentWriter in project mongo-java-driver by mongodb.
the class CommandMonitoringTestHelper method getWritableCloneOfCommand.
private static BsonDocument getWritableCloneOfCommand(final BsonDocument original) {
BsonDocument clone = new BsonDocument();
BsonDocumentWriter writer = new BsonDocumentWriter(clone);
new BsonDocumentCodec(CODEC_REGISTRY_HACK).encode(writer, original, EncoderContext.builder().build());
return clone;
}
Aggregations