Jiabao-Sun commented on code in PR #1: URL: https://github.com/apache/flink-connector-mongodb/pull/1#discussion_r1052145855
########## 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: Thanks @twalthr. The `JsonWriter` cannot directly write a `BsonValue` in to a string. It will throw an exception when writing directly to a `BsonValue`, so we used `_value` to wrap the bson value into a bson document. However, we can also extend a `JsonWriter` so that it does not check when writing bson value directly. Do you think we need to customize a `JsonWriter`? ```java package org.apache.flink; import org.bson.BsonRegularExpression; import org.bson.json.JsonWriter; import java.io.IOException; import java.io.StringWriter; public class JsonWriterTest { public static void main(String[] args) throws IOException { try (StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(stringWriter)) { BsonRegularExpression regularExpression = new BsonRegularExpression("regex", "i"); jsonWriter.writeRegularExpression(regularExpression); } } } ``` ```shell Exception in thread "main" org.bson.BsonInvalidOperationException: A RegularExpression value cannot be written to the root level of a BSON document. at org.bson.AbstractBsonWriter.throwInvalidState(AbstractBsonWriter.java:740) at org.bson.AbstractBsonWriter.checkPreconditions(AbstractBsonWriter.java:701) at org.bson.AbstractBsonWriter.writeRegularExpression(AbstractBsonWriter.java:590) at org.apache.flink.JsonWriterTest.main(JsonWriterTest.java:15) ``` -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org