github-actions[bot] commented on code in PR #64741:
URL: https://github.com/apache/doris/pull/64741#discussion_r3459413123


##########
fs_brokers/cdc_client/src/main/java/org/apache/doris/cdcclient/source/deserialize/DebeziumJsonDeserializer.java:
##########
@@ -412,19 +412,50 @@ private Object convertToArray(Schema fieldSchema, Object 
dbzObj) {
         return dbzObj.toString();
     }
 
+    // Format a since-midnight time value given as total microseconds (may be 
negative or exceed
+    // 24h) as MySQL TIME literal text: ±HH:MM:SS[.ffffff], stripping trailing 
fractional zeros.
+    private static String formatTimeText(long microsTotal) {
+        boolean negative = microsTotal < 0;
+        long abs = Math.abs(microsTotal);
+        long hours = abs / 3_600_000_000L;
+        long rem = abs % 3_600_000_000L;
+        long minutes = rem / 60_000_000L;
+        rem %= 60_000_000L;
+        long seconds = rem / 1_000_000L;
+        long frac = rem % 1_000_000L;
+        String sign = negative ? "-" : "";
+        if (frac == 0) {
+            return String.format("%s%02d:%02d:%02d", sign, hours, minutes, 
seconds);

Review Comment:
   `String.format` uses the JVM default locale, so this new out-of-range path 
can emit localized digits when the cdc-client process runs with a locale such 
as Arabic. These values need to remain stable ASCII database time literals like 
`12:34:56`, but `String.format("%02d:%02d:%02d", 12, 34, 56)` is 
locale-dependent. Please format these strings with `Locale.ROOT` or a 
locale-independent formatter/scanner for all three `String.format` calls in 
`formatTimeText`.



##########
fs_brokers/cdc_client/src/test/java/org/apache/doris/cdcclient/itcase/PostgresTypeConsistencyITCase.java:
##########
@@ -0,0 +1,196 @@
+// 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.doris.cdcclient.itcase;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.doris.cdcclient.common.Env;
+import org.apache.doris.job.cdc.split.SnapshotSplit;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * PostgreSQL counterpart of {@link MySqlTypeConsistencyITCase}: the same 
value inserted before
+ * capture (snapshot, JDBC path) and after (binlog, logical-decoding path) 
must deserialize
+ * identically per column. JSON/JSONB are compared by parsed value to tolerate 
whitespace/key-order
+ * differences while still catching a genuinely different value.
+ */
+@Testcontainers
+class PostgresTypeConsistencyITCase {
+
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+    private static final AtomicLong JOB_ID_SEQ = new AtomicLong(595_000);
+
+    // Identical column tuple for both the snapshot row (id 1) and the binlog 
row (id 2).
+    private static final String VALUES =
+            "12345678901234.567890,"            // c_numeric NUMERIC(20,6)
+                    + "1.5,"                    // c_real REAL
+                    + "3.141592653589793,"      // c_double DOUBLE PRECISION
+                    + "true,"                   // c_bool BOOLEAN
+                    + "'hello',"                // c_text TEXT
+                    + "'world',"                // c_varchar VARCHAR(20)
+                    + "'abcde',"                // c_char CHAR(5)
+                    + "'{\"k\": 1, \"a\": [2, 3]}',"  // c_json JSON
+                    + "'{\"k\": 1, \"a\": [2, 3]}',"  // c_jsonb JSONB
+                    + "B'10100101',"            // c_bit BIT(8)
+                    + "B'101',"                 // c_varbit VARBIT(16)
+                    + "'\\x0102030405',"        // c_bytea BYTEA
+                    + "'11111111-1111-1111-1111-111111111111',"  // c_uuid UUID
+                    + "'2023-08-15',"           // c_date DATE
+                    + "'12:34:56.123456',"      // c_time TIME(6)
+                    + "'12:34:56.123456+08',"   // c_timetz TIMETZ
+                    + "'2023-08-15 12:34:56.123456',"     // c_timestamp 
TIMESTAMP(6)
+                    + "'2023-08-15 12:34:56.123456+08',"  // c_timestamptz 
TIMESTAMPTZ
+                    + "'1 day 02:03:04',"       // c_interval INTERVAL
+                    + "'192.168.0.1',"          // c_inet INET
+                    + "'{1,2,3}',"              // c_int_arr INT[]
+                    + "'{a,b}',"                // c_text_arr TEXT[]
+                    + "'12.34'";                // c_money MONEY
+
+    @Container
+    static final PostgreSQLContainer<?> POSTGRES =
+            new PostgreSQLContainer<>(DockerImageName.parse("postgres:14"))
+                    .withCommand("postgres", "-c", "wal_level=logical");
+
+    private String jobId;
+    private String table;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        jobId = String.valueOf(JOB_ID_SEQ.incrementAndGet());
+        table = "t_scan_" + jobId;
+        try (Connection conn = connect();
+                Statement st = conn.createStatement()) {
+            st.execute("DROP TABLE IF EXISTS " + table);
+            st.execute(
+                    "CREATE TABLE " + table + " ("
+                            + "id INT PRIMARY KEY,"
+                            + "c_numeric NUMERIC(20,6),"
+                            + "c_real REAL,"
+                            + "c_double DOUBLE PRECISION,"
+                            + "c_bool BOOLEAN,"
+                            + "c_text TEXT,"
+                            + "c_varchar VARCHAR(20),"
+                            + "c_char CHAR(5),"
+                            + "c_json JSON,"
+                            + "c_jsonb JSONB,"
+                            + "c_bit BIT(8),"
+                            + "c_varbit VARBIT(16),"
+                            + "c_bytea BYTEA,"
+                            + "c_uuid UUID,"
+                            + "c_date DATE,"
+                            + "c_time TIME(6),"
+                            + "c_timetz TIMETZ,"
+                            + "c_timestamp TIMESTAMP(6),"
+                            + "c_timestamptz TIMESTAMPTZ,"
+                            + "c_interval INTERVAL,"
+                            + "c_inet INET,"
+                            + "c_int_arr INT[],"
+                            + "c_text_arr TEXT[],"
+                            + "c_money MONEY)");
+            st.execute("ALTER TABLE " + table + " REPLICA IDENTITY FULL");
+            st.execute("INSERT INTO " + table + " VALUES (1," + VALUES + ")");
+        }
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        Env.getCurrentEnv().close(jobId);
+        try (Connection conn = connect();
+                Statement st = conn.createStatement()) {
+            st.execute("DROP TABLE IF EXISTS " + table);
+        }
+    }
+
+    @Test
+    void snapshotAndBinlogDeserializeIdentically() throws Exception {
+        try (CdcClientReadHarness harness =
+                CdcClientReadHarness.postgres(
+                        jobId,
+                        POSTGRES.getHost(),
+                        
POSTGRES.getMappedPort(PostgreSQLContainer.POSTGRESQL_PORT),
+                        POSTGRES.getUsername(),
+                        POSTGRES.getPassword(),
+                        POSTGRES.getDatabaseName(),
+                        "public",
+                        table,
+                        "initial")) {
+
+            List<SnapshotSplit> splits = harness.fetchAllSnapshotSplits(table);
+            CdcClientReadHarness.SnapshotResult snapshot = 
harness.readSnapshot(splits);
+            JsonNode snap = MAPPER.readTree(snapshot.records().get(0));
+
+            try (Connection conn = connect();
+                    Statement st = conn.createStatement()) {
+                st.execute("INSERT INTO " + table + " VALUES (2," + VALUES + 
")");
+            }
+            List<String> binlog = harness.readBinlogUntil(snapshot, splits, 1, 
Duration.ofSeconds(60));
+            JsonNode bin = MAPPER.readTree(binlog.get(0));
+
+            List<String> mismatches = new ArrayList<>();
+            Iterator<String> fields = snap.fieldNames();
+            while (fields.hasNext()) {
+                String col = fields.next();
+                if (col.equals("id") || col.startsWith("__DORIS")) {
+                    continue;
+                }
+                String snapVal = snap.get(col).asText();

Review Comment:
   This comparison loses the contents of the PostgreSQL array columns added by 
this test. `c_int_arr` and `c_text_arr` are parsed as JSON arrays, and Jackson 
returns `""` for `ArrayNode.asText()`, so a regression like `[1,2,3]` vs 
`[1,2,4]` would compare equal and never be reported. Please compare container 
nodes directly, or canonicalize them with `toString()` before the existing 
parsed-JSON fallback, so the array columns are actually covered by the 
type-consistency test.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to