Search in sources :

Example 36 with BsonDocumentReader

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

the class TestBsonRecordReader method testStringType.

@Test
public void testStringType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("stringKey", new BsonString("test_string"));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals("test_string", mapReader.reader("stringKey").readText().toString());
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonString(org.bson.BsonString) BsonDocumentReader(org.bson.BsonDocumentReader) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 37 with BsonDocumentReader

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

the class TestBsonRecordReader method testSpecialCharStringType.

@Test
public void testSpecialCharStringType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("stringKey", new BsonString("§§§§§§§§§1"));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals("§§§§§§§§§1", mapReader.reader("stringKey").readText().toString());
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonString(org.bson.BsonString) BsonDocumentReader(org.bson.BsonDocumentReader) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 38 with BsonDocumentReader

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

the class DBCollection method distinct.

/**
 * Find the distinct values for a specified field across a collection and returns the results in an array.
 *
 * @param fieldName  Specifies the field for which to return the distinct values
 * @param options    the options to apply for this operation
 * @return A {@code List} of the distinct values
 * @mongodb.driver.manual reference/command/distinct Distinct Command
 * @since 3.4
 */
@SuppressWarnings("unchecked")
public List distinct(final String fieldName, final DBCollectionDistinctOptions options) {
    notNull("fieldName", fieldName);
    return new MongoIterableImpl<BsonValue>(null, executor, options.getReadConcern() != null ? options.getReadConcern() : getReadConcern(), options.getReadPreference() != null ? options.getReadPreference() : getReadPreference(), retryReads) {

        @Override
        public ReadOperation<BatchCursor<BsonValue>> asReadOperation() {
            return new DistinctOperation<BsonValue>(getNamespace(), fieldName, new BsonValueCodec()).filter(wrapAllowNull(options.getFilter())).collation(options.getCollation()).retryReads(retryReads);
        }
    }.map(new Function<BsonValue, Object>() {

        @Override
        public Object apply(final BsonValue bsonValue) {
            if (bsonValue == null) {
                return null;
            }
            BsonDocument document = new BsonDocument("value", bsonValue);
            DBObject obj = getDefaultDBObjectCodec().decode(new BsonDocumentReader(document), DecoderContext.builder().build());
            return obj.get("value");
        }
    }).into(new ArrayList<Object>());
}
Also used : BsonValueCodec(org.bson.codecs.BsonValueCodec) BatchCursor(com.mongodb.internal.operation.BatchCursor) MapReduceBatchCursor(com.mongodb.internal.operation.MapReduceBatchCursor) BsonDocument(org.bson.BsonDocument) BsonDocumentReader(org.bson.BsonDocumentReader) MongoIterableImpl(com.mongodb.client.internal.MongoIterableImpl) BsonValue(org.bson.BsonValue)

Example 39 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project immutables by immutables.

the class JacksonCodecsTest method bsonDocument.

/**
 * Reading directly {@link BsonDocument}
 */
@Test
public void bsonDocument() throws IOException {
    final CodecRegistry registry = JacksonCodecs.registryFromMapper(mapper);
    BsonDocument expected = new BsonDocument("a", new BsonInt32(1));
    BsonDocument actual = registry.get(BsonDocument.class).decode(new BsonDocumentReader(expected), DecoderContext.builder().build());
    check(actual).is(expected);
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonDocumentReader(org.bson.BsonDocumentReader) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) Test(org.junit.jupiter.api.Test)

Example 40 with BsonDocumentReader

use of org.bson.BsonDocumentReader in project immutables by immutables.

the class JacksonCodecsTest method document.

/**
 * Reading directly {@link Document}
 */
@Test
public void document() throws IOException {
    final CodecRegistry registry = JacksonCodecs.registryFromMapper(mapper);
    Document expected = new Document("a", 1);
    Document actual = registry.get(Document.class).decode(new BsonDocumentReader(expected.toBsonDocument(BsonDocument.class, registry)), DecoderContext.builder().build());
    check(actual).is(expected);
}
Also used : BsonDocumentReader(org.bson.BsonDocumentReader) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) Test(org.junit.jupiter.api.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