From 53288276b966fb6b1e3bd1f3f4199de5ebbb4b71 Mon Sep 17 00:00:00 2001 From: Dinu John <86094133+dinujoh@users.noreply.github.com> Date: Fri, 10 May 2024 09:16:10 -0500 Subject: [PATCH] Use time in seconds for BsonTimeStamp field when converting to record --- .../dataprepper/plugins/mongo/client/BsonHelper.java | 2 +- .../dataprepper/plugins/mongo/client/BsonHelperTest.java | 2 +- .../dataprepper/plugins/mongo/stream/StreamWorkerTest.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelper.java b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelper.java index 3f3f656e24..6b8e11c4c6 100644 --- a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelper.java +++ b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelper.java @@ -102,7 +102,7 @@ public class BsonHelper { writer.writeString(REGEX_OPTIONS, value.getOptions()); writer.writeEndObject(); }) - .timestampConverter((value, writer) -> writer.writeNumber(String.valueOf(value.getValue()))) + .timestampConverter((value, writer) -> writer.writeNumber(String.valueOf(value.getTime()))) .undefinedConverter((value, writer) -> writer.writeNull()) .build(); diff --git a/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelperTest.java b/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelperTest.java index 90838f5620..13253c77c5 100644 --- a/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelperTest.java +++ b/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/client/BsonHelperTest.java @@ -343,7 +343,7 @@ private static Stream mongoDataTypeProvider() { "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"objectIdField\": \"6634ed693ac62386d57b12d0\"}"), Arguments.of( "{\"_id\": { \"$oid\": \"6634ed693ac62386d57bcaf0\" }, \"timestampField\": { \"$timestamp\": {\"t\": 1714744681, \"i\": 29}}}", - "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"timestampField\": 7364772325884952605}"), + "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"timestampField\": 1714744681}"), Arguments.of( "{\"_id\": { \"$oid\": \"6634ed693ac62386d57bcaf0\" }, \"regexField\": { \"$regularExpression\": {\"pattern\": \"^ABC\", \"options\": \"i\"}}}", "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"regexField\": {\"pattern\": \"^ABC\", \"options\": \"i\"}}"), diff --git a/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/stream/StreamWorkerTest.java b/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/stream/StreamWorkerTest.java index 3837b2c145..dfe7063d76 100644 --- a/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/stream/StreamWorkerTest.java +++ b/data-prepper-plugins/mongodb/src/test/java/org/opensearch/dataprepper/plugins/mongo/stream/StreamWorkerTest.java @@ -505,9 +505,9 @@ private static Stream mongoDataTypeProvider() { new BsonTimestamp(Math.abs(random.nextLong())), "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"doubleValue\": 3.14159}"), Arguments.of( - "{\"_id\": { \"$oid\": \"6634ed693ac62386d57bcaf0\" }, \"longValue\": { \"$numberLong\": \"1234567890123456768\"}}", + "{\"_id\": { \"$oid\": \"6634ed693ac62386d57bcaf0\" }, \"longValue\": { \"$numberLong\": \"9223372036854775801\"}}", new BsonObjectId(new ObjectId()), - "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"longValue\": 1234567890123456768}"), + "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"longValue\": 9223372036854775801}"), Arguments.of( "{\"_id\": { \"$oid\": \"6634ed693ac62386d57bcaf0\" }, \"stringField\": \"Hello, Mongo!\"}", new BsonDocument(), @@ -539,7 +539,7 @@ private static Stream mongoDataTypeProvider() { Arguments.of( "{\"_id\": { \"$oid\": \"6634ed693ac62386d57bcaf0\" }, \"timestampField\": { \"$timestamp\": {\"t\": 1714744681, \"i\": 29}}}", new BsonObjectId(new ObjectId()), - "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"timestampField\": 7364772325884952605}"), + "{\"_id\": \"6634ed693ac62386d57bcaf0\", \"timestampField\": 1714744681}"), Arguments.of( "{\"_id\": { \"$oid\": \"6634ed693ac62386d57bcaf0\" }, \"regexField\": { \"$regularExpression\": {\"pattern\": \"^ABC\", \"options\": \"i\"}}}", new BsonObjectId(new ObjectId()),