Copilot commented on code in PR #17145:
URL: 
https://github.com/apache/dolphinscheduler/pull/17145#discussion_r2052054449


##########
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/param/PostgreSQLDataSourceProcessor.java:
##########
@@ -132,7 +132,62 @@ public DataSourceProcessor create() {
     @Override
     public List<String> splitAndRemoveComment(String sql) {
         String cleanSQL = SQLParserUtils.removeComment(sql, 
com.alibaba.druid.DbType.postgresql);
-        return SQLParserUtils.split(cleanSQL, 
com.alibaba.druid.DbType.postgresql);
+        return splitSqlRespectingDollarQuotes(cleanSQL);
+    }
+
+    private List<String> splitSqlRespectingDollarQuotes(String sql) {
+        List<String> result = new ArrayList<>();
+        StringBuilder current = new StringBuilder();
+
+        boolean insideDollarBlock = false;
+        String dollarTag = null;
+        int i = 0;
+
+        while (i < sql.length()) {
+            char ch = sql.charAt(i);
+
+            // Detect start of dollar-quote block (e.g. $DO$, $func$, etc.)
+            if (!insideDollarBlock && ch == '$') {
+                int start = i;
+                int end = sql.indexOf('$', start + 1);
+                if (end > start) {
+                    String tag = sql.substring(start, end + 1); // includes 
both $
+                    if (sql.substring(end + 1).contains(tag)) {

Review Comment:
   The check for a closing dollar quote using substring.contains(tag) may cause 
false positives if the tag appears in non-delimiter contexts (e.g., within 
string literals). Consider using a more robust method, such as a regular 
expression or a stateful parser, to accurately determine the block boundaries.
   ```suggestion
                       String regex = "\\Q" + tag + "\\E"; // Escape the tag 
for regex
                       if (sql.substring(end + 1).matches(".*" + regex + ".*")) 
{
   ```



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

Reply via email to