This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 743b6e90a3 [flink] Fix ClassCastException in MongoDB CDC JsonPath 
extraction (#6113)
743b6e90a3 is described below

commit 743b6e90a324b58f07832eea8680e5b9afb7da07
Author: Arnav Balyan <[email protected]>
AuthorDate: Wed Aug 27 07:45:22 2025 +0530

    [flink] Fix ClassCastException in MongoDB CDC JsonPath extraction (#6113)
---
 .../cdc/mongodb/strategy/MongoVersionStrategy.java |  5 +-
 .../mongodb/strategy/MongoVersionStrategyTest.java | 80 ++++++++++++++++++++++
 2 files changed, 83 insertions(+), 2 deletions(-)

diff --git 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/mongodb/strategy/MongoVersionStrategy.java
 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/mongodb/strategy/MongoVersionStrategy.java
index baea947276..a41a1eec68 100644
--- 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/mongodb/strategy/MongoVersionStrategy.java
+++ 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/mongodb/strategy/MongoVersionStrategy.java
@@ -133,8 +133,9 @@ public interface MongoVersionStrategy {
         Map<String, String> parsedRow = new HashMap<>();
 
         for (int i = 0; i < parseNames.length; i++) {
-            String evaluate = JsonPath.read(record, parseNames[i]);
-            parsedRow.put(columnNames[i], 
Optional.ofNullable(evaluate).orElse("{}"));
+            Object evaluate = JsonPath.read(record, parseNames[i]);
+            String stringValue = evaluate != null ? evaluate.toString() : null;
+            parsedRow.put(columnNames[i], 
Optional.ofNullable(stringValue).orElse("{}"));
         }
 
         return processParsedData(parsedRow, schemaBuilder, computedColumns);
diff --git 
a/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/mongodb/strategy/MongoVersionStrategyTest.java
 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/mongodb/strategy/MongoVersionStrategyTest.java
new file mode 100644
index 0000000000..ea45a2041c
--- /dev/null
+++ 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/mongodb/strategy/MongoVersionStrategyTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.strategy;
+
+import org.apache.paimon.flink.sink.cdc.CdcSchema;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test for {@link MongoVersionStrategy}. */
+class MongoVersionStrategyTest {
+
+    @Test
+    void testParseFieldsFromJsonRecordWithDoubleValue() {
+        String record =
+                "{"
+                        + "\n  \"_id\": {\"$oid\": 
\"507f1f77bcf86cd799439011\"},"
+                        + "\n  \"name\": \"John Doe\","
+                        + "\n  \"age\": 30,"
+                        + "\n  \"price\": 19.99,"
+                        + "\n  \"active\": true"
+                        + "\n}";
+
+        String fieldPaths = "$.name,$.age,$.price,$.active";
+        String fieldNames = "name,age,price,active";
+
+        CdcSchema.Builder schemaBuilder = CdcSchema.newBuilder();
+
+        Map<String, String> result =
+                MongoVersionStrategy.parseFieldsFromJsonRecord(
+                        record, fieldPaths, fieldNames, 
Collections.emptyList(), schemaBuilder);
+
+        assertThat(result).containsEntry("name", "John Doe");
+        assertThat(result).containsEntry("age", "30");
+        assertThat(result).containsEntry("price", "19.99");
+        assertThat(result).containsEntry("active", "true");
+    }
+
+    @Test
+    void testParseFieldsFromJsonRecordWithStringValues() {
+        String record =
+                "{"
+                        + "\n  \"_id\": {\"$oid\": 
\"507f1f77bcf86cd799439011\"},"
+                        + "\n  \"name\": \"John Doe\","
+                        + "\n  \"description\": \"A sample record\""
+                        + "\n}";
+
+        String fieldPaths = "$.name,$.description";
+        String fieldNames = "name,description";
+
+        CdcSchema.Builder schemaBuilder = CdcSchema.newBuilder();
+
+        Map<String, String> result =
+                MongoVersionStrategy.parseFieldsFromJsonRecord(
+                        record, fieldPaths, fieldNames, 
Collections.emptyList(), schemaBuilder);
+
+        assertThat(result).containsEntry("name", "John Doe");
+        assertThat(result).containsEntry("description", "A sample record");
+    }
+}

Reply via email to