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());
}
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());
}
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>());
}
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);
}
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);
}
Aggregations