Search in sources :

Example 76 with BsonDocument

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());
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) BsonTimestamp(org.bson.BsonTimestamp) Test(org.junit.Test)

Example 77 with BsonDocument

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());
}
Also used : BsonNull(org.bson.BsonNull) BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) Test(org.junit.Test)

Example 78 with BsonDocument

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));
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) BsonDocumentReader(org.bson.BsonDocumentReader) BsonObjectId(org.bson.BsonObjectId) Test(org.junit.Test)

Example 79 with BsonDocument

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);
}
Also used : BsonElement(org.bson.BsonElement) BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList)

Example 80 with BsonDocument

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);
}
Also used : BsonDocument(org.bson.BsonDocument) BsonJavaScriptWithScope(org.bson.BsonJavaScriptWithScope)

Aggregations

BsonDocument (org.bson.BsonDocument)169 BsonString (org.bson.BsonString)53 BsonValue (org.bson.BsonValue)37 Test (org.junit.Test)36 BsonArray (org.bson.BsonArray)29 BsonInt32 (org.bson.BsonInt32)28 ArrayList (java.util.ArrayList)24 BsonDocumentReader (org.bson.BsonDocumentReader)17 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)14 BsonDocumentWriter (org.bson.BsonDocumentWriter)14 BsonInt64 (org.bson.BsonInt64)14 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)10 BsonDouble (org.bson.BsonDouble)8 Document (org.bson.Document)7 MongoNamespace (com.mongodb.MongoNamespace)6 Before (org.junit.Before)6 MongoGridFSException (com.mongodb.MongoGridFSException)5 BsonObjectId (org.bson.BsonObjectId)5 BsonWriter (org.bson.BsonWriter)5 ObjectId (org.bson.types.ObjectId)5