MonsterChenzhuo commented on code in PR #1809: URL: https://github.com/apache/incubator-paimon/pull/1809#discussion_r1295632361
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/mongodb/JsonParserUtils.java: ########## @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.flink.action.cdc.mongodb; + +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonFactory; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonParser; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.type.MapType; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * specified, and return json string of the extracted json object. It will return null if the input + * json string is invalid. A limited version of JSONPath supported: $ : Root object . : Child + * operator [] : Subscript operator for array * : Wildcard for [] Syntax not supported that's worth + * noticing: '' : Zero length string as key .. : Recursive descent @ : Current + * object/element () : Script expression ?() : Filter (script) expression. [,] : Union operator + * [start:end:step] : array slice operator. + */ +@SuppressWarnings("unchecked") +public class JsonParserUtils implements Serializable { Review Comment: I have not seen an implementation of nested JSON parsing in JsonSerdeUtil, for example: ```json { "_id":"{\"_id\": {\"_id\": {\"$oid\": \"643e9943fa4dfe102cfcfa61\"}}}", "operationType":"delete", "fullDocument":null, "fullDocumentBeforeChange":null, "source":{ "ts_ms":1691562432000, "snapshot":"false" }, "ts_ms":1691562432255, "ns":{ "db":"test", "coll":"temp3" }, "to":null, "documentKey":"{\"_id\": {\"$oid\": \"643e9943fa4dfe102cfcfa61\"}}", "updateDescription":null, "clusterTime":"{\"$timestamp\": {\"t\": 1691562432, \"i\": 66}}", "txnNumber":null, "lsid":null } ``` When I want to retrieve the `snapshot` value, I can use the `evaluate` method from `JsonParserUtils` and pass the parsing path: source.snapshot When I want to obtain the `db` value, I should pass the parsing path: ns[0].db -- 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]
