Copilot commented on code in PR #62269:
URL: https://github.com/apache/doris/pull/62269#discussion_r3056245950


##########
fe/fe-core/src/main/java/org/apache/doris/job/offset/jdbc/JdbcSourceOffsetProvider.java:
##########
@@ -568,6 +568,40 @@ protected boolean isSnapshotOnlyMode() {
         return DataSourceConfigKeys.OFFSET_SNAPSHOT.equalsIgnoreCase(offset);
     }
 
+    @Override
+    public String getLag() {
+        if (currentOffset == null || currentOffset.snapshotSplit()) {
+            return "";
+        }
+        BinlogSplit binlogSplit = (BinlogSplit) 
currentOffset.getSplits().get(0);

Review Comment:
   `getSplits().get(0)` can throw `IndexOutOfBoundsException` if 
`currentOffset.getSplits()` is empty, and the cast to `BinlogSplit` can throw 
`ClassCastException` if the split type is not `BinlogSplit`. Since this runs on 
the `SHOW JOBS` / TVF path, an exception here can break job listing. Add guards 
to return `""` when splits are empty or when the first split isn’t a 
`BinlogSplit` (or locate the correct `BinlogSplit` from the list).
   ```suggestion
           List<AbstractSourceSplit> splits = currentOffset.getSplits();
           if (CollectionUtils.isEmpty(splits)) {
               return "";
           }
           BinlogSplit binlogSplit = null;
           for (AbstractSourceSplit split : splits) {
               if (split instanceof BinlogSplit) {
                   binlogSplit = (BinlogSplit) split;
                   break;
               }
           }
           if (binlogSplit == null) {
               return "";
           }
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/job/offset/jdbc/JdbcSourceOffsetProvider.java:
##########
@@ -568,6 +568,40 @@ protected boolean isSnapshotOnlyMode() {
         return DataSourceConfigKeys.OFFSET_SNAPSHOT.equalsIgnoreCase(offset);
     }
 
+    @Override
+    public String getLag() {
+        if (currentOffset == null || currentOffset.snapshotSplit()) {
+            return "";
+        }
+        BinlogSplit binlogSplit = (BinlogSplit) 
currentOffset.getSplits().get(0);
+        Map<String, String> offsetMap = binlogSplit.getStartingOffset();
+        if (MapUtils.isEmpty(offsetMap)) {
+            return "";
+        }
+        long eventTimeMs = extractEventTimeMs(offsetMap);
+        if (eventTimeMs <= 0) {
+            return "";
+        }
+        long lagSec = (System.currentTimeMillis() - eventTimeMs) / 1000;
+        return String.valueOf(Math.max(lagSec, 0));
+    }
+
+    /**
+     * Extract event timestamp in milliseconds from binlog offset map.
+     * MySQL: ts_sec (seconds), PostgreSQL: ts_usec (microseconds).
+     */
+    protected long extractEventTimeMs(Map<String, String> offsetMap) {
+        String tsSec = offsetMap.get("ts_sec");
+        if (tsSec != null) {
+            return Long.parseLong(tsSec) * 1000;
+        }
+        String tsUsec = offsetMap.get("ts_usec");
+        if (tsUsec != null) {
+            return Long.parseLong(tsUsec) / 1000;

Review Comment:
   `Long.parseLong(...)` can throw `NumberFormatException` if the offset value 
is missing/empty/corrupted. Because this is called from `getLag()` (TVF 
output), that exception can bubble up and fail `jobs()` / `SHOW JOBS`. Handle 
parsing failures (e.g., catch `NumberFormatException` and return `-1` / `""`) 
so the lag column degrades gracefully instead of breaking the query.
   ```suggestion
               try {
                   return Long.parseLong(tsSec) * 1000;
               } catch (NumberFormatException e) {
                   return -1;
               }
           }
           String tsUsec = offsetMap.get("ts_usec");
           if (tsUsec != null) {
               try {
                   return Long.parseLong(tsUsec) / 1000;
               } catch (NumberFormatException e) {
                   return -1;
               }
   ```



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