Jiabao-Sun commented on code in PR #1:
URL: 
https://github.com/apache/flink-connector-mongodb/pull/1#discussion_r1052209447


##########
flink-connector-mongodb/src/test/java/org/apache/flink/connector/mongodb/table/converter/MongoConvertersTest.java:
##########
@@ -146,28 +146,31 @@ public void testConvertBsonToRowData() {
                 GenericRowData.of(
                         StringData.fromString(oid.toHexString()),
                         StringData.fromString("string"),
-                        StringData.fromString(uuid.toString()),
+                        StringData.fromString(
+                                "{\"_value\": {\"$binary\": {\"base64\": 
\"gR+qXamERr+L0IyxvO9daQ==\", \"subType\": \"04\"}}}"),
                         2,
                         3L,
                         4.1d,
                         DecimalData.fromBigDecimal(new BigDecimal("5.1"), 10, 
2),
                         false,
                         TimestampData.fromEpochMillis(now.getEpochSecond() * 
1000),
+                        TimestampData.fromEpochMillis(now.toEpochMilli()),
                         StringData.fromString(
-                                OffsetDateTime.ofInstant(
-                                                
Instant.ofEpochMilli(now.toEpochMilli()),
-                                                ZoneOffset.UTC)
-                                        .format(ISO_OFFSET_DATE_TIME)),
-                        StringData.fromString("/^9$/i"),
-                        StringData.fromString("function() { return 10; }"),
-                        StringData.fromString("function() { return 11; }"),
-                        StringData.fromString("12"),
-                        StringData.fromString(oid.toHexString()),
+                                "{\"_value\": {\"$regularExpression\": 
{\"pattern\": \"^9$\", \"options\": \"i\"}}}"),

Review Comment:
   The current bson api only supports the conversion of bson document. For a 
single bson value, we need to customize `JsonWriter` and `JsonReader`.
   So in the previous implementation, we used a _value to wrap a single bson 
value as a bson document, so that we can parse them easily.
   
   ```java
   import org.bson.BsonDocument;
   import org.bson.BsonRegularExpression;
   import org.bson.json.JsonMode;
   import org.bson.json.JsonWriterSettings;
   import org.junit.jupiter.api.Test;
   
   import static org.junit.jupiter.api.Assertions.assertEquals;
   
   public class JsonConversionTest {
   
       @Test
       public void bsonToJsonTest() {
           BsonRegularExpression original = new BsonRegularExpression("regex", 
"i");
           BsonDocument wrapped = new BsonDocument("_value", original);
   
           String json = 
wrapped.toJson(JsonWriterSettings.builder().outputMode(JsonMode.EXTENDED).build());
           // {"_value": {"$regularExpression": {"pattern": "regex", "options": 
"i"}}}
           System.out.println(json);
   
           BsonDocument parsed = BsonDocument.parse(json);
           BsonRegularExpression parsedRegularExpression = 
parsed.getRegularExpression("_value");
   
           assertEquals(parsedRegularExpression, original);
       }
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to