You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "macdoor (via GitHub)" <gi...@apache.org> on 2026/02/21 12:30:14 UTC

[PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

macdoor opened a new pull request, #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987

   ## Purpose of the pull request
   
   Add parameter replacement support for **Flink** and **Flink Stream** task plugins. `initScript` and `rawScript` can use DolphinScheduler built-in and custom parameters (e.g. `${system.biz.date}`, `${localParams.xxx}`), consistent with other task types.
   
   ## Brief change log
   
   - In `FlinkTask` and `FlinkStreamTask`, apply `ParameterUtils.convertParameterPlaceholders()` to `initScript` and `rawScript` in `init()` using `taskExecutionContext.getPrepareParamsMap()`
   - Add unit tests (`FlinkTaskTest`, `FlinkStreamTaskTest`) to verify parameter replacement for `${var}` placeholders and `$[yyyyMMdd]` time expressions
   - No new dependencies; reuses existing `ParameterUtils` and task API
   
   ## Verify this pull request
   
   This change added tests and can be verified as follows:
   
   - Added `FlinkTaskTest` and `FlinkStreamTaskTest` with test cases:
     - `testInitReplacesPlaceholdersInInitScriptAndRawScript()`: Verifies `${var}` replacement with custom parameters
     - `testInitReplacesTimePlaceholderWhenParamMapContainsScheduleTime()`: Verifies `$[yyyyMMdd]` time placeholder replacement
   - Run tests: `mvn test -pl dolphinscheduler-task-plugin/dolphinscheduler-task-flink,dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream -Dtest=FlinkTaskTest,FlinkStreamTaskTest`
   - Manually verified: Create a Flink (or Flink Stream) task with placeholders in init script or main script (e.g. `${system.biz.date}`), run the workflow and confirm the placeholders are replaced correctly at runtime
   
   ## Pull Request Notice
   
   [Pull Request Notice](https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
   
   If your pull request contains incompatible change, you should also add it to `docs/docs/en/guide/upgrade/incompatible.md`
   
   ---
   
   closes #17986


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "macdoor (via GitHub)" <gi...@apache.org>.
macdoor commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2850686264


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTaskTest.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkStreamTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */
+public class FlinkStreamTaskTest {
+
+    @TempDir
+    Path tempDir;
+
+    @Test
+    public void testParameterReplacementInScript() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-app";
+
+        FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("SET 'date' = '${bizdate}';");
+        flinkParameters.setRawScript("SELECT * FROM logs WHERE dt = '${bizdate}' AND env = '${env}'");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put("bizdate", new Property("bizdate", null, null, "20250601"));
+        prepareParamsMap.put("env", new Property("env", null, null, "prod"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkStreamTaskForTest task = new FlinkStreamTaskForTest(context);
+        task.init();
+        task.callGetScript();
+
+        String initScriptPath = String.format("%s/%s_init.sql", executePath, taskAppId);
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+
+        String initContent = Files.readString(Path.of(initScriptPath), StandardCharsets.UTF_8);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(initContent.contains("SET 'date' = '20250601';"),
+                "Expected ${bizdate} to be replaced, got: " + initContent);
+        Assertions.assertTrue(nodeContent.contains("dt = '20250601'"),
+                "Expected ${bizdate} to be replaced, got: " + nodeContent);
+        Assertions.assertTrue(nodeContent.contains("env = 'prod'"),
+                "Expected ${env} to be replaced, got: " + nodeContent);
+    }
+
+    @Test
+    public void testParameterReplacementTimePlaceholder() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-time";
+
+        FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("");
+        flinkParameters.setRawScript("INSERT INTO t SELECT * FROM s WHERE dt = '$[yyyyMMdd]'");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put(PARAMETER_DATETIME, new Property(PARAMETER_DATETIME, null, null, "20210815080000"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkStreamTaskForTest task = new FlinkStreamTaskForTest(context);
+        task.init();
+        task.callGetScript();
+
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(nodeContent.contains("dt = '20210815'"),
+                "Expected $[yyyyMMdd] to be replaced with 20210815, got: " + nodeContent);
+    }
+
+    private static class FlinkStreamTaskForTest extends FlinkStreamTask {
+
+        FlinkStreamTaskForTest(TaskExecutionContext context) {
+            super(context);
+        }
+
+        String callGetScript() {
+            return getScript();
+        }
+    }

Review Comment:
   solved. thx



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun merged PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3939950392

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [86.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [8.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2845269485


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTask.java:
##########
@@ -48,6 +52,20 @@ public FlinkStreamTask(TaskExecutionContext taskExecutionContext) {
     public void init() {
 
         flinkParameters = JSONUtils.parseObject(taskExecutionContext.getTaskParams(), FlinkStreamParameters.class);
+        // Replace parameter placeholders (e.g. ${system.biz.date}, $[yyyyMMdd]) in init script and main script
+        if (flinkParameters != null) {
+            Map<String, Property> paramsMap = taskExecutionContext.getPrepareParamsMap();
+            Map<String, String> stringParams = ParameterUtils.convert(paramsMap);
+
+            if (StringUtils.isNotBlank(flinkParameters.getInitScript())) {
+                flinkParameters.setInitScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getInitScript(), stringParams));
+            }
+            if (StringUtils.isNotBlank(flinkParameters.getRawScript())) {
+                flinkParameters.setRawScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getRawScript(), stringParams));
+            }
+        }

Review Comment:
   It's better move to line 74.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkTask.java:
##########
@@ -57,6 +62,21 @@ public FlinkTask(TaskExecutionContext taskExecutionContext) {
     public void init() {
 
         flinkParameters = JSONUtils.parseObject(taskExecutionContext.getTaskParams(), FlinkParameters.class);
+        // Replace parameter placeholders (e.g. ${system.biz.date}, $[yyyyMMdd]) in init script and main script
+        if (flinkParameters != null) {
+            Map<String, Property> paramsMap = taskExecutionContext.getPrepareParamsMap();
+            Map<String, String> stringParams = ParameterUtils.convert(paramsMap);
+
+            if (StringUtils.isNotBlank(flinkParameters.getInitScript())) {
+                flinkParameters.setInitScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getInitScript(), stringParams));
+            }
+            if (StringUtils.isNotBlank(flinkParameters.getRawScript())) {
+                flinkParameters.setRawScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getRawScript(), stringParams));
+            }
+        }

Review Comment:
   It's better move to line 85.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/pom.xml:
##########
@@ -45,6 +45,22 @@
             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-inline</artifactId>
+            <scope>test</scope>
+        </dependency>

Review Comment:
   This has already defined at root pom, do we still need to add here?



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/pom.xml:
##########
@@ -51,6 +51,22 @@
             <artifactId>dolphinscheduler-task-flink</artifactId>
             <version>${project.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-inline</artifactId>
+            <scope>test</scope>
+        </dependency>

Review Comment:
   This has already defined at root pom, do we still need to add here?



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "macdoor (via GitHub)" <gi...@apache.org>.
macdoor commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2850856768


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkTaskTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */

Review Comment:
   solved.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3979618679

   Awesome work, congrats on your first merged pull request!
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "macdoor (via GitHub)" <gi...@apache.org>.
macdoor commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2846768460


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/pom.xml:
##########
@@ -45,6 +45,22 @@
             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-inline</artifactId>
+            <scope>test</scope>
+        </dependency>

Review Comment:
   solved



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/pom.xml:
##########
@@ -51,6 +51,22 @@
             <artifactId>dolphinscheduler-task-flink</artifactId>
             <version>${project.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-inline</artifactId>
+            <scope>test</scope>
+        </dependency>

Review Comment:
   solved



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2850345737


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTaskTest.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkStreamTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */
+public class FlinkStreamTaskTest {
+
+    @TempDir
+    Path tempDir;
+
+    @Test
+    public void testParameterReplacementInScript() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-app";
+
+        FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("SET 'date' = '${bizdate}';");
+        flinkParameters.setRawScript("SELECT * FROM logs WHERE dt = '${bizdate}' AND env = '${env}'");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put("bizdate", new Property("bizdate", null, null, "20250601"));
+        prepareParamsMap.put("env", new Property("env", null, null, "prod"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkStreamTaskForTest task = new FlinkStreamTaskForTest(context);
+        task.init();
+        task.callGetScript();
+
+        String initScriptPath = String.format("%s/%s_init.sql", executePath, taskAppId);
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+
+        String initContent = Files.readString(Path.of(initScriptPath), StandardCharsets.UTF_8);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(initContent.contains("SET 'date' = '20250601';"),
+                "Expected ${bizdate} to be replaced, got: " + initContent);
+        Assertions.assertTrue(nodeContent.contains("dt = '20250601'"),
+                "Expected ${bizdate} to be replaced, got: " + nodeContent);
+        Assertions.assertTrue(nodeContent.contains("env = 'prod'"),
+                "Expected ${env} to be replaced, got: " + nodeContent);
+    }
+
+    @Test
+    public void testParameterReplacementTimePlaceholder() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-time";
+
+        FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("");
+        flinkParameters.setRawScript("INSERT INTO t SELECT * FROM s WHERE dt = '$[yyyyMMdd]'");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put(PARAMETER_DATETIME, new Property(PARAMETER_DATETIME, null, null, "20210815080000"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkStreamTaskForTest task = new FlinkStreamTaskForTest(context);
+        task.init();
+        task.callGetScript();
+
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(nodeContent.contains("dt = '20210815'"),
+                "Expected $[yyyyMMdd] to be replaced with 20210815, got: " + nodeContent);
+    }
+
+    private static class FlinkStreamTaskForTest extends FlinkStreamTask {
+
+        FlinkStreamTaskForTest(TaskExecutionContext context) {
+            super(context);
+        }
+
+        String callGetScript() {
+            return getScript();
+        }
+    }

Review Comment:
   Why not directly execute `task.getSctipt()` at line 107.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3976178711

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [10 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [93.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3977228791

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [10 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [93.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3948740189

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [86.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [8.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2850695912


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkTaskTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */
+public class FlinkTaskTest {
+
+    @TempDir
+    Path tempDir;
+
+    @Test
+    public void testParameterReplacementInScript() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-app";
+
+        FlinkParameters flinkParameters = new FlinkParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("set batch_size=${batch_size};");
+        flinkParameters.setRawScript("SELECT * FROM logs WHERE dt='$[yyyyMMdd]';");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put("batch_size", new Property("batch_size", null, null, "1000"));
+        prepareParamsMap.put(PARAMETER_DATETIME, new Property(PARAMETER_DATETIME, null, null, "20201201120000"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkTask task = new FlinkTask(context);
+        task.init();
+        task.getScript();
+
+        String initScriptPath = String.format("%s/%s_init.sql", executePath, taskAppId);
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+
+        String initContent = Files.readString(Path.of(initScriptPath), StandardCharsets.UTF_8);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(initContent.contains("set batch_size=1000;"),
+                "Expected ${batch_size} to be replaced with 1000, got: " + initContent);
+        Assertions.assertTrue(nodeContent.contains("dt='20201201'"),
+                "Expected $[yyyyMMdd] to be replaced with 20201201, got: " + nodeContent);

Review Comment:
   Do not use contains; use the equals assertion directly.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkTaskTest.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTaskTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkStreamTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */
+public class FlinkStreamTaskTest {
+
+    @TempDir
+    Path tempDir;
+
+    @Test
+    public void testParameterReplacementInScript() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-app";
+
+        FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("SET 'date' = '${bizdate}';");
+        flinkParameters.setRawScript("SELECT * FROM logs WHERE dt = '${bizdate}' AND env = '${env}'");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put("bizdate", new Property("bizdate", null, null, "20250601"));
+        prepareParamsMap.put("env", new Property("env", null, null, "prod"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkStreamTask task = new FlinkStreamTask(context);
+        task.init();
+        task.getScript();
+
+        String initScriptPath = String.format("%s/%s_init.sql", executePath, taskAppId);
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+
+        String initContent = Files.readString(Path.of(initScriptPath), StandardCharsets.UTF_8);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(initContent.contains("SET 'date' = '20250601';"),
+                "Expected ${bizdate} to be replaced, got: " + initContent);
+        Assertions.assertTrue(nodeContent.contains("dt = '20250601'"),
+                "Expected ${bizdate} to be replaced, got: " + nodeContent);
+        Assertions.assertTrue(nodeContent.contains("env = 'prod'"),
+                "Expected ${env} to be replaced, got: " + nodeContent);
+    }
+
+    @Test
+    public void testParameterReplacementTimePlaceholder() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-time";
+
+        FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("");
+        flinkParameters.setRawScript("INSERT INTO t SELECT * FROM s WHERE dt = '$[yyyyMMdd]'");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put(PARAMETER_DATETIME, new Property(PARAMETER_DATETIME, null, null, "20210815080000"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkStreamTask task = new FlinkStreamTask(context);
+        task.init();
+        task.getScript();
+
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(nodeContent.contains("dt = '20210815'"),
+                "Expected $[yyyyMMdd] to be replaced with 20210815, got: " + nodeContent);

Review Comment:
   Do not use contains; use the equals assertion directly.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTaskTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkStreamTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/test/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTaskTest.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.dolphinscheduler.plugin.task.flink;
+
+import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_DATETIME;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * FlinkStreamTask unit test. Verifies parameter replacement in initScript and rawScript without Mockito.
+ */
+public class FlinkStreamTaskTest {
+
+    @TempDir
+    Path tempDir;
+
+    @Test
+    public void testParameterReplacementInScript() throws Exception {
+        String executePath = tempDir.toString();
+        String taskAppId = "test-app";
+
+        FlinkStreamParameters flinkParameters = new FlinkStreamParameters();
+        flinkParameters.setProgramType(ProgramType.SQL);
+        flinkParameters.setDeployMode(FlinkDeployMode.LOCAL);
+        flinkParameters.setParallelism(2);
+        flinkParameters.setInitScript("SET 'date' = '${bizdate}';");
+        flinkParameters.setRawScript("SELECT * FROM logs WHERE dt = '${bizdate}' AND env = '${env}'");
+
+        Map<String, Property> prepareParamsMap = new HashMap<>();
+        prepareParamsMap.put("bizdate", new Property("bizdate", null, null, "20250601"));
+        prepareParamsMap.put("env", new Property("env", null, null, "prod"));
+
+        TaskExecutionContext context = new TaskExecutionContext();
+        context.setTaskParams(JSONUtils.toJsonString(flinkParameters));
+        context.setExecutePath(executePath);
+        context.setTaskAppId(taskAppId);
+        context.setPrepareParamsMap(prepareParamsMap);
+
+        FlinkStreamTask task = new FlinkStreamTask(context);
+        task.init();
+        task.getScript();
+
+        String initScriptPath = String.format("%s/%s_init.sql", executePath, taskAppId);
+        String nodeScriptPath = String.format("%s/%s_node.sql", executePath, taskAppId);
+
+        String initContent = Files.readString(Path.of(initScriptPath), StandardCharsets.UTF_8);
+        String nodeContent = Files.readString(Path.of(nodeScriptPath), StandardCharsets.UTF_8);
+
+        Assertions.assertTrue(initContent.contains("SET 'date' = '20250601';"),
+                "Expected ${bizdate} to be replaced, got: " + initContent);
+        Assertions.assertTrue(nodeContent.contains("dt = '20250601'"),
+                "Expected ${bizdate} to be replaced, got: " + nodeContent);
+        Assertions.assertTrue(nodeContent.contains("env = 'prod'"),
+                "Expected ${env} to be replaced, got: " + nodeContent);

Review Comment:
   Do not use contains; use the equals assertion directly.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3948743917

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [86.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [8.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "macdoor (via GitHub)" <gi...@apache.org>.
macdoor commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2846810848


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink-stream/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkStreamTask.java:
##########
@@ -48,6 +52,20 @@ public FlinkStreamTask(TaskExecutionContext taskExecutionContext) {
     public void init() {
 
         flinkParameters = JSONUtils.parseObject(taskExecutionContext.getTaskParams(), FlinkStreamParameters.class);
+        // Replace parameter placeholders (e.g. ${system.biz.date}, $[yyyyMMdd]) in init script and main script
+        if (flinkParameters != null) {
+            Map<String, Property> paramsMap = taskExecutionContext.getPrepareParamsMap();
+            Map<String, String> stringParams = ParameterUtils.convert(paramsMap);
+
+            if (StringUtils.isNotBlank(flinkParameters.getInitScript())) {
+                flinkParameters.setInitScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getInitScript(), stringParams));
+            }
+            if (StringUtils.isNotBlank(flinkParameters.getRawScript())) {
+                flinkParameters.setRawScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getRawScript(), stringParams));
+            }
+        }

Review Comment:
   solved



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3976178522

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [10 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [93.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3938710613

   Thanks for opening this pull request! Please check out our contributing guidelines. (https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3939947910

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [86.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [8.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "macdoor (via GitHub)" <gi...@apache.org>.
macdoor commented on code in PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#discussion_r2846814372


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FlinkTask.java:
##########
@@ -57,6 +62,21 @@ public FlinkTask(TaskExecutionContext taskExecutionContext) {
     public void init() {
 
         flinkParameters = JSONUtils.parseObject(taskExecutionContext.getTaskParams(), FlinkParameters.class);
+        // Replace parameter placeholders (e.g. ${system.biz.date}, $[yyyyMMdd]) in init script and main script
+        if (flinkParameters != null) {
+            Map<String, Property> paramsMap = taskExecutionContext.getPrepareParamsMap();
+            Map<String, String> stringParams = ParameterUtils.convert(paramsMap);
+
+            if (StringUtils.isNotBlank(flinkParameters.getInitScript())) {
+                flinkParameters.setInitScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getInitScript(), stringParams));
+            }
+            if (StringUtils.isNotBlank(flinkParameters.getRawScript())) {
+                flinkParameters.setRawScript(
+                        ParameterUtils.convertParameterPlaceholders(flinkParameters.getRawScript(), stringParams));
+            }
+        }

Review Comment:
   solved. thx



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-17986][task-plugin] Support parameter replacement in Flink and FlinkStream task [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17987:
URL: https://github.com/apache/dolphinscheduler/pull/17987#issuecomment-3977231091

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [10 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17987&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [93.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17987&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17987)
   
   


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org