Search in sources :

Example 1 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project mongo-java-driver by mongodb.

the class ListCollectionsOperation method projectFromFullNamespaceToCollectionName.

private List<T> projectFromFullNamespaceToCollectionName(final List<BsonDocument> unstripped) {
    if (unstripped == null) {
        return null;
    }
    List<T> stripped = new ArrayList<T>(unstripped.size());
    String prefix = databaseName + ".";
    for (BsonDocument cur : unstripped) {
        String name = cur.getString("name").getValue();
        String collectionName = name.substring(prefix.length());
        cur.put("name", new BsonString(collectionName));
        stripped.add(decoder.decode(new BsonDocumentReader(cur), DecoderContext.builder().build()));
    }
    return stripped;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) ArrayList(java.util.ArrayList) BsonDocumentReader(org.bson.BsonDocumentReader) BsonString(org.bson.BsonString)

Example 2 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project mongo-java-driver by mongodb.

the class FindOperation method documentToQueryResult.

private QueryResult<T> documentToQueryResult(final BsonDocument result, final ServerAddress serverAddress) {
    QueryResult<T> queryResult;
    if (isExplain()) {
        T decodedDocument = decoder.decode(new BsonDocumentReader(result), DecoderContext.builder().build());
        queryResult = new QueryResult<T>(getNamespace(), Collections.singletonList(decodedDocument), 0, serverAddress);
    } else {
        queryResult = cursorDocumentToQueryResult(result.getDocument("cursor"), serverAddress);
    }
    return queryResult;
}
Also used : BsonDocumentReader(org.bson.BsonDocumentReader)

Example 3 with BsonDocumentReader

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

Example 4 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project drill by axbaretto.

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 5 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project drill by axbaretto.

the class TestBsonRecordReader method testDateTimeType.

@Test
public void testDateTimeType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("dateTimeKey", new BsonDateTime(5262729712L));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(5262729712L, mapReader.reader("dateTimeKey").readDateTime().getMillis());
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDateTime(org.bson.BsonDateTime) BsonDocumentReader(org.bson.BsonDocumentReader) Test(org.junit.Test)

Aggregations

BsonDocumentReader (org.bson.BsonDocumentReader)43 BsonDocument (org.bson.BsonDocument)42 Test (org.junit.Test)30 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)29 BaseTest (org.apache.drill.test.BaseTest)15 BsonString (org.bson.BsonString)9 FieldReader (org.apache.drill.exec.vector.complex.reader.FieldReader)6 BsonDocumentWriter (org.bson.BsonDocumentWriter)6 BsonWriter (org.bson.BsonWriter)6 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)3 BsonBoolean (org.bson.BsonBoolean)3 BsonDateTime (org.bson.BsonDateTime)3 BsonDouble (org.bson.BsonDouble)3 BsonInt32 (org.bson.BsonInt32)3 BsonInt64 (org.bson.BsonInt64)3 BsonNull (org.bson.BsonNull)3 ProjectedTuple (org.immutables.criteria.backend.ProjectedTuple)3 Path (org.immutables.criteria.expression.Path)3 Query (org.immutables.criteria.expression.Query)3