Search in sources :

Example 6 with BsonInt64

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

the class AggregateToCollectionOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName()));
    commandDocument.put("pipeline", new BsonArray(pipeline));
    if (maxTimeMS > 0) {
        commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
    }
    if (allowDiskUse != null) {
        commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
    }
    if (bypassDocumentValidation != null && serverIsAtLeastVersionThreeDotTwo(description)) {
        commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation));
    }
    if (serverIsAtLeastVersionThreeDotSix(description)) {
        commandDocument.put("cursor", new BsonDocument());
    }
    appendWriteConcernToCommand(writeConcern, commandDocument, description);
    if (collation != null) {
        commandDocument.put("collation", collation.asDocument());
    }
    return commandDocument;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray)

Example 7 with BsonInt64

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

the class TestBsonRecordReader method testIntType.

@Test
public void testIntType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("seqNo", new BsonInt64(10));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(10l, mapReader.reader("seqNo").readLong().longValue());
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) Test(org.junit.Test)

Example 8 with BsonInt64

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

the class TestBsonRecordReader method testIntType.

@Test
public void testIntType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("seqNo", new BsonInt64(10));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(10L, mapReader.reader("seqNo").readLong().longValue());
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 9 with BsonInt64

use of org.bson.BsonInt64 in project pinpoint by naver.

the class WritecontextTest method parseBsonArrayWithValues.

@Test
public void parseBsonArrayWithValues() throws IOException {
    BsonValue a = new BsonString("stest");
    BsonValue b = new BsonDouble(111);
    BsonValue c = new BsonBoolean(true);
    BsonDocument document = new BsonDocument().append("int32", new BsonInt32(12)).append("int64", new BsonInt64(77L)).append("bo\"olean", new BsonBoolean(true)).append("date", new BsonDateTime(new Date().getTime())).append("double", new BsonDouble(12.3)).append("string", new BsonString("pinpoint")).append("objectId", new BsonObjectId(new ObjectId())).append("code", new BsonJavaScript("int i = 10;")).append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))).append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")).append("symbol", new BsonSymbol("wow")).append("timestamp", new BsonTimestamp(0x12345678, 5)).append("undefined", new BsonUndefined()).append("binary1", new BsonBinary(new byte[] { (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20 })).append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[] { 1, 1, 1, 1, 1 })).append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))).append("document", new BsonDocument("a", new BsonInt32(77))).append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())).append("null", new BsonNull()).append("decimal128", new BsonDecimal128(new Decimal128(55)));
    BasicDBObject query = new BasicDBObject();
    query.put("ComplexBson", document);
    logger.debug("document:{}", document);
    NormalizedBson stringStringValue = MongoUtil.parseBson(new Object[] { query }, true);
    logger.debug("val:{}", stringStringValue);
    List list = objectMapper.readValue("[" + stringStringValue.getNormalizedBson() + "]", List.class);
    Assert.assertEquals(list.size(), 1);
    Map<String, ?> query1Map = (Map<String, ?>) list.get(0);
    checkValue(query1Map);
}
Also used : BsonString(org.bson.BsonString) BsonBoolean(org.bson.BsonBoolean) BasicDBObject(com.mongodb.BasicDBObject) BsonInt32(org.bson.BsonInt32) BsonDecimal128(org.bson.BsonDecimal128) BsonDouble(org.bson.BsonDouble) ArrayList(java.util.ArrayList) List(java.util.List) BsonJavaScriptWithScope(org.bson.BsonJavaScriptWithScope) BsonNull(org.bson.BsonNull) BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) BsonBinary(org.bson.BsonBinary) BsonDbPointer(org.bson.BsonDbPointer) Decimal128(org.bson.types.Decimal128) BsonDecimal128(org.bson.BsonDecimal128) BsonRegularExpression(org.bson.BsonRegularExpression) BsonObjectId(org.bson.BsonObjectId) BsonJavaScript(org.bson.BsonJavaScript) Date(java.util.Date) BsonTimestamp(org.bson.BsonTimestamp) BsonInt64(org.bson.BsonInt64) BsonSymbol(org.bson.BsonSymbol) BsonDocument(org.bson.BsonDocument) BsonDateTime(org.bson.BsonDateTime) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) Map(java.util.Map) BsonUndefined(org.bson.BsonUndefined) BsonValue(org.bson.BsonValue) Test(org.junit.Test)

Example 10 with BsonInt64

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

the class FindOperation method getCommand.

private BsonDocument getCommand(final SessionContext sessionContext, final int maxWireVersion) {
    BsonDocument commandDocument = new BsonDocument("find", new BsonString(namespace.getCollectionName()));
    appendReadConcernToCommand(sessionContext, maxWireVersion, commandDocument);
    putIfNotNull(commandDocument, "filter", filter);
    putIfNotNullOrEmpty(commandDocument, "sort", sort);
    putIfNotNullOrEmpty(commandDocument, "projection", projection);
    if (skip > 0) {
        commandDocument.put("skip", new BsonInt32(skip));
    }
    if (limit != 0) {
        commandDocument.put("limit", new BsonInt32(Math.abs(limit)));
    }
    if (limit >= 0) {
        if (batchSize < 0 && Math.abs(batchSize) < limit) {
            commandDocument.put("limit", new BsonInt32(Math.abs(batchSize)));
        } else if (batchSize != 0) {
            commandDocument.put("batchSize", new BsonInt32(Math.abs(batchSize)));
        }
    }
    if (limit < 0 || batchSize < 0) {
        commandDocument.put("singleBatch", BsonBoolean.TRUE);
    }
    if (maxTimeMS > 0) {
        commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
    }
    if (isTailableCursor()) {
        commandDocument.put("tailable", BsonBoolean.TRUE);
    }
    if (isAwaitData()) {
        commandDocument.put("awaitData", BsonBoolean.TRUE);
    }
    if (oplogReplay) {
        commandDocument.put("oplogReplay", BsonBoolean.TRUE);
    }
    if (noCursorTimeout) {
        commandDocument.put("noCursorTimeout", BsonBoolean.TRUE);
    }
    if (partial) {
        commandDocument.put("allowPartialResults", BsonBoolean.TRUE);
    }
    if (collation != null) {
        commandDocument.put("collation", collation.asDocument());
    }
    if (comment != null) {
        commandDocument.put("comment", new BsonString(comment));
    }
    if (hint != null) {
        commandDocument.put("hint", hint);
    }
    if (max != null) {
        commandDocument.put("max", max);
    }
    if (min != null) {
        commandDocument.put("min", min);
    }
    if (returnKey) {
        commandDocument.put("returnKey", BsonBoolean.TRUE);
    }
    if (showRecordId) {
        commandDocument.put("showRecordId", BsonBoolean.TRUE);
    }
    if (allowDiskUse != null) {
        commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
    }
    return commandDocument;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Aggregations

BsonInt64 (org.bson.BsonInt64)44 BsonDocument (org.bson.BsonDocument)36 BsonString (org.bson.BsonString)30 BsonInt32 (org.bson.BsonInt32)20 BsonArray (org.bson.BsonArray)16 BsonDouble (org.bson.BsonDouble)13 BsonValue (org.bson.BsonValue)11 Test (org.junit.Test)7 MongoNamespace (com.mongodb.MongoNamespace)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)3 BsonDocumentReader (org.bson.BsonDocumentReader)3 BsonRegularExpression (org.bson.BsonRegularExpression)3 ObjectId (org.bson.types.ObjectId)3 Test (org.junit.jupiter.api.Test)3 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)2 BsonBoolean (org.bson.BsonBoolean)2 BsonDateTime (org.bson.BsonDateTime)2 BsonNull (org.bson.BsonNull)2