use of org.bson.BsonDateTime 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());
}
use of org.bson.BsonDateTime 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);
}
use of org.bson.BsonDateTime in project mongo-java-driver by mongodb.
the class IdHoldingBsonWriter method writeDateTime.
@Override
public void writeDateTime(final String name, final long value) {
setCurrentFieldName(name);
addBsonValue(() -> new BsonDateTime(value), () -> getIdBsonWriter().writeDateTime(name, value));
super.writeDateTime(name, value);
}
use of org.bson.BsonDateTime in project mongo-java-driver by mongodb.
the class GridFSFileCodec method encode.
@Override
public void encode(final BsonWriter writer, final GridFSFile value, final EncoderContext encoderContext) {
BsonDocument bsonDocument = new BsonDocument();
bsonDocument.put("_id", value.getId());
bsonDocument.put("filename", new BsonString(value.getFilename()));
bsonDocument.put("length", new BsonInt64(value.getLength()));
bsonDocument.put("chunkSize", new BsonInt32(value.getChunkSize()));
bsonDocument.put("uploadDate", new BsonDateTime(value.getUploadDate().getTime()));
Document metadata = value.getMetadata();
if (metadata != null) {
bsonDocument.put("metadata", new BsonDocumentWrapper<Document>(metadata, documentCodec));
}
bsonDocumentCodec.encode(writer, bsonDocument, encoderContext);
}
use of org.bson.BsonDateTime in project immutables by immutables.
the class JavaTimeTypeTest method instant.
@Test
void instant() {
InstantHolderRepository repository = new InstantHolderRepository(backend);
Instant value = Instant.now();
ImmutableInstantHolder holder = TypeHolder.InstantHolder.generator().get().withValue(value).withOptional(value).withNullable(null);
repository.insert(holder);
BsonDocument doc = fetch();
BsonDateTime expected = new BsonDateTime(value.toEpochMilli());
check(doc.get("value")).is(expected);
check(doc.get("optional")).is(expected);
if (doc.containsKey("nullable")) {
check(doc.get("nullable")).is(BsonNull.VALUE);
}
}
Aggregations