use of org.bson.BsonDocument in project drill by apache.
the class TestBsonRecordReader method testTimeStampType.
@Test
public void testTimeStampType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
bsonDoc.append("ts", new BsonTimestamp(1000, 10));
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
assertEquals(1000l, mapReader.reader("ts").readDateTime().getMillis());
}
use of org.bson.BsonDocument in project drill by apache.
the class TestBsonRecordReader method testNullType.
@Test
public void testNullType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
bsonDoc.append("nullKey", new BsonNull());
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
assertEquals(null, mapReader.reader("nullKey").readObject());
}
use of org.bson.BsonDocument in project drill by apache.
the class TestBsonRecordReader method testObjectIdType.
@Test
public void testObjectIdType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonObjectId value = new BsonObjectId(new ObjectId());
bsonDoc.append("_idKey", value);
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
assertTrue(Arrays.equals(value.getValue().toByteArray(), readByteArray));
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class BsonDocumentCodec method decode.
@Override
public BsonDocument decode(final BsonReader reader, final DecoderContext decoderContext) {
List<BsonElement> keyValuePairs = new ArrayList<BsonElement>();
reader.readStartDocument();
while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
String fieldName = reader.readName();
keyValuePairs.add(new BsonElement(fieldName, readValue(reader, decoderContext)));
}
reader.readEndDocument();
return new BsonDocument(keyValuePairs);
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class BsonJavaScriptWithScopeCodec method decode.
@Override
public BsonJavaScriptWithScope decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
String code = bsonReader.readJavaScriptWithScope();
BsonDocument scope = documentCodec.decode(bsonReader, decoderContext);
return new BsonJavaScriptWithScope(code, scope);
}
Aggregations