Search in sources :

Example 1 with BsonDecimal128

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

the class TestBsonRecordReader method testDecimal128Type.

@Test
public void testDecimal128Type() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("decimal128Key", new BsonDecimal128(Decimal128.parse("12.12345624")));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(new BigDecimal("12.12345624"), mapReader.reader("decimal128Key").readBigDecimal());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDecimal128(org.bson.BsonDecimal128) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDocumentReader(org.bson.BsonDocumentReader) BigDecimal(java.math.BigDecimal) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 2 with BsonDecimal128

use of org.bson.BsonDecimal128 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 3 with BsonDecimal128

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

the class IdHoldingBsonWriter method writeDecimal128.

@Override
public void writeDecimal128(final String name, final Decimal128 value) {
    setCurrentFieldName(name);
    addBsonValue(() -> new BsonDecimal128(value), () -> getIdBsonWriter().writeDecimal128(name, value));
    super.writeDecimal128(name, value);
}
Also used : BsonDecimal128(org.bson.BsonDecimal128)

Example 4 with BsonDecimal128

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

the class TypeConversionTest method decimal128.

@Test
void decimal128() throws IOException {
    BsonDecimal128 value = new BsonDecimal128(new Decimal128(BigDecimal.valueOf(1.1)));
    check(Parsers.parserAt(value).getCurrentToken()).is(JsonToken.VALUE_NUMBER_FLOAT);
    check(Parsers.parserAt(value).getNumberType()).is(JsonParser.NumberType.BIG_DECIMAL);
    check(Parsers.parserAt(value).getDoubleValue()).is(1.1);
    check(Parsers.parserAt(value).getDecimalValue()).is(BigDecimal.valueOf(1.1));
}
Also used : BsonDecimal128(org.bson.BsonDecimal128) Decimal128(org.bson.types.Decimal128) BsonDecimal128(org.bson.BsonDecimal128) Test(org.junit.jupiter.api.Test)

Example 5 with BsonDecimal128

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

the class BsonDecimal128Test method read.

@Test
public void read() throws Exception {
    BsonDocument doc = new BsonDocument();
    doc.put("int", new BsonDecimal128(Decimal128.parse(Integer.toString(Integer.MAX_VALUE))));
    doc.put("long", new BsonDecimal128(new Decimal128(Long.MAX_VALUE)));
    doc.put("double", new BsonDecimal128(Decimal128.parse("12.111")));
    JsonReader reader = Jsons.asGsonReader(doc);
    reader.beginObject();
    check(reader.nextName()).is("int");
    check(reader.peek()).is(JsonToken.NUMBER);
    check(reader.nextInt()).is(Integer.MAX_VALUE);
    check(reader.nextName()).is("long");
    check(reader.peek()).is(JsonToken.NUMBER);
    check(reader.nextLong()).is(Long.MAX_VALUE);
    check(reader.nextName()).is("double");
    check(reader.peek()).is(JsonToken.NUMBER);
    check(reader.nextDouble()).is(12.111D);
    reader.endObject();
    reader.close();
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDecimal128(org.bson.BsonDecimal128) JsonReader(com.google.gson.stream.JsonReader) BsonDecimal128(org.bson.BsonDecimal128) Decimal128(org.bson.types.Decimal128) Test(org.junit.Test)

Aggregations

BsonDecimal128 (org.bson.BsonDecimal128)8 BsonDocument (org.bson.BsonDocument)5 Decimal128 (org.bson.types.Decimal128)5 Test (org.junit.Test)3 BsonArray (org.bson.BsonArray)2 BsonDouble (org.bson.BsonDouble)2 BsonInt64 (org.bson.BsonInt64)2 BsonString (org.bson.BsonString)2 Test (org.junit.jupiter.api.Test)2 JsonReader (com.google.gson.stream.JsonReader)1 BasicDBObject (com.mongodb.BasicDBObject)1 ExpectedAnnotation (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation)1 StringStringValue (com.navercorp.pinpoint.common.util.StringStringValue)1 NormalizedBson (com.navercorp.pinpoint.plugin.mongo.NormalizedBson)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1