github-advanced-security[bot] commented on code in PR #4418:
URL: https://github.com/apache/streampark/pull/4418#discussion_r3540528931


##########
streampark-flink/streampark-flink-packer/src/main/java/org/apache/streampark/flink/packer/pipeline/impl/FlinkYarnApplicationBuildPipeline.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.streampark.flink.packer.pipeline.impl;
+
+import org.apache.streampark.common.conf.Workspace;
+import org.apache.streampark.common.enums.FlinkJobType;
+import org.apache.streampark.common.fs.FsOperator;
+import org.apache.streampark.common.fs.HdfsOperator;
+import org.apache.streampark.common.fs.LfsOperator;
+import org.apache.streampark.flink.packer.maven.MavenTool;
+import org.apache.streampark.flink.packer.pipeline.*;
+
+import org.apache.commons.codec.digest.DigestUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class FlinkYarnApplicationBuildPipeline extends BuildPipeline {
+    private final FlinkYarnApplicationBuildRequest request;
+    public FlinkYarnApplicationBuildPipeline(FlinkYarnApplicationBuildRequest 
request) { this.request = request; }
+    public static FlinkYarnApplicationBuildPipeline 
of(FlinkYarnApplicationBuildRequest request) { return new 
FlinkYarnApplicationBuildPipeline(request); }
+    @Override public PipelineTypeEnum getPipeType() { return 
PipelineTypeEnum.FLINK_YARN_APPLICATION; }
+    @Override protected BuildParam offerBuildParam() { return request; }
+    @Override protected BuildResult buildProcess() throws Throwable {
+        execStep(1, () -> {
+            if (request.flinkJobType() == FlinkJobType.FLINK_SQL || 
request.flinkJobType() == FlinkJobType.PYFLINK) {
+                
LfsOperator.getInstance().mkCleanDirs(request.localWorkspace());
+                
HdfsOperator.getInstance().mkCleanDirs(request.yarnProvidedPath());
+            }
+            return null;
+        }).orElseThrow(() -> getError().exception());
+        List<String> mavenJars = execStep(2, () -> {
+            if (request.flinkJobType() == FlinkJobType.FLINK_SQL || 
request.flinkJobType() == FlinkJobType.PYFLINK) {
+                List<String> paths = new ArrayList<>();
+                
MavenTool.resolveArtifacts(request.dependencyInfo().mavenArts()).forEach(f -> 
paths.add(f.getAbsolutePath()));
+                paths.addAll(request.dependencyInfo().extJarLibs());
+                return paths;
+            }
+            return Collections.<String>emptyList();
+        }).orElseThrow(() -> getError().exception());
+        execStep(3, () -> {
+            for (String jar : mavenJars) {
+                uploadJarToHdfsOrLfs(FsOperator.lfs(), jar, 
request.localWorkspace());
+                uploadJarToHdfsOrLfs(FsOperator.hdfs(), jar, 
request.yarnProvidedPath());
+            }
+            return null;
+        }).orElseThrow(() -> getError().exception());
+        return new SimpleBuildResponse();
+    }
+
+    private void uploadJarToHdfsOrLfs(FsOperator fsOperator, String origin, 
String target) throws Exception {
+        File originFile = new File(origin);
+        if (!fsOperator.exists(target)) fsOperator.mkdirs(target);
+        if (originFile.isFile()) {
+            if (fsOperator == FsOperator.lfs()) {
+                fsOperator.copy(originFile.getAbsolutePath(), target);
+            } else {
+                String uploadFile = Workspace.remote().APP_UPLOADS() + "/" + 
originFile.getName();
+                if (fsOperator.exists(uploadFile)) {
+                    try (FileInputStream in = new FileInputStream(originFile)) 
{
+                        if 
(!DigestUtils.md5Hex(in).equals(fsOperator.fileMd5(uploadFile))) {

Review Comment:
   ## SonarCloud / Weak hashing algorithms should not be used
   
   <!--SONAR_ISSUE_KEY:AZ89C2oxrLZzqHYtjN8y-->Make sure this weak hash 
algorithm is not used in a sensitive context here. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_incubator-streampark&issues=AZ89C2oxrLZzqHYtjN8y&open=AZ89C2oxrLZzqHYtjN8y&pullRequest=4418";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/streampark/security/code-scanning/166)



##########
streampark-flink/streampark-flink-packer/src/main/java/org/apache/streampark/flink/packer/pipeline/impl/SparkYarnBuildPipeline.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.streampark.flink.packer.pipeline.impl;
+
+import org.apache.streampark.common.conf.Workspace;
+import org.apache.streampark.common.enums.SparkJobType;
+import org.apache.streampark.common.fs.FsOperator;
+import org.apache.streampark.common.fs.HdfsOperator;
+import org.apache.streampark.common.fs.LfsOperator;
+import org.apache.streampark.flink.packer.maven.MavenTool;
+import org.apache.streampark.flink.packer.pipeline.BuildParam;
+import org.apache.streampark.flink.packer.pipeline.BuildPipeline;
+import org.apache.streampark.flink.packer.pipeline.BuildResult;
+import org.apache.streampark.flink.packer.pipeline.PipelineTypeEnum;
+import org.apache.streampark.flink.packer.pipeline.SimpleBuildResponse;
+import org.apache.streampark.flink.packer.pipeline.SparkYarnBuildRequest;
+
+import org.apache.commons.codec.digest.DigestUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/** Building pipeline for spark yarn application mode. */
+public class SparkYarnBuildPipeline extends BuildPipeline {
+
+    private final SparkYarnBuildRequest request;
+
+    public SparkYarnBuildPipeline(SparkYarnBuildRequest request) {
+        this.request = request;
+    }
+
+    public static SparkYarnBuildPipeline of(SparkYarnBuildRequest request) {
+        return new SparkYarnBuildPipeline(request);
+    }
+
+    @Override
+    public PipelineTypeEnum getPipeType() {
+        return PipelineTypeEnum.SPARK_CLUSTER;
+    }
+
+    @Override
+    protected BuildParam offerBuildParam() {
+        return request;
+    }
+
+    @Override
+    protected BuildResult buildProcess() throws Throwable {
+        execStep(
+                        1,
+                        () -> {
+                            if (request.jobType() == SparkJobType.SPARK_SQL) {
+                                
LfsOperator.getInstance().mkCleanDirs(request.localWorkspace());
+                                
HdfsOperator.getInstance().mkCleanDirs(request.yarnProvidedPath());
+                            }
+                            return null;
+                        })
+                .orElseThrow(() -> getError().exception());
+
+        List<String> mavenJars =
+                execStep(
+                                2,
+                                () -> {
+                                    if (request.jobType() == 
SparkJobType.SPARK_SQL) {
+                                        List<String> paths = new ArrayList<>();
+                                        
MavenTool.resolveArtifacts(request.dependencyInfo().mavenArts())
+                                                .forEach(f -> 
paths.add(f.getAbsolutePath()));
+                                        
paths.addAll(request.dependencyInfo().extJarLibs());
+                                        return paths;
+                                    }
+                                    return Collections.<String>emptyList();
+                                })
+                        .orElseThrow(() -> getError().exception());
+
+        execStep(
+                        3,
+                        () -> {
+                            for (String jar : mavenJars) {
+                                uploadJarToHdfsOrLfs(
+                                        FsOperator.lfs(), jar, 
request.localWorkspace());
+                                uploadJarToHdfsOrLfs(
+                                        FsOperator.hdfs(), jar, 
request.yarnProvidedPath());
+                            }
+                            return null;
+                        })
+                .orElseThrow(() -> getError().exception());
+        return new SimpleBuildResponse();
+    }
+
+    private void uploadJarToHdfsOrLfs(FsOperator fsOperator, String origin, 
String target)
+            throws Exception {
+        File originFile = new File(origin);
+        if (!fsOperator.exists(target)) {
+            fsOperator.mkdirs(target);
+        }
+        if (originFile.isFile()) {
+            if (fsOperator == FsOperator.lfs()) {
+                fsOperator.copy(originFile.getAbsolutePath(), target);
+            } else {
+                String uploadFile =
+                        Workspace.remote().APP_UPLOADS() + "/" + 
originFile.getName();
+                if (fsOperator.exists(uploadFile)) {
+                    try (FileInputStream in = new FileInputStream(originFile)) 
{
+                        if 
(!DigestUtils.md5Hex(in).equals(fsOperator.fileMd5(uploadFile))) {

Review Comment:
   ## SonarCloud / Weak hashing algorithms should not be used
   
   <!--SONAR_ISSUE_KEY:AZ89C2pIrLZzqHYtjN80-->Make sure this weak hash 
algorithm is not used in a sensitive context here. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_incubator-streampark&issues=AZ89C2pIrLZzqHYtjN80&open=AZ89C2pIrLZzqHYtjN80&pullRequest=4418";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/streampark/security/code-scanning/167)



##########
streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/java/org/apache/streampark/flink/core/conf/ParameterCli.java:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.streampark.flink.core.conf;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+import org.apache.streampark.common.util.PropertiesUtils;
+
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Options;
+
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** Parses Flink application CLI parameters from configuration files. */
+public final class ParameterCli {
+
+    private static final String PROPERTY_PREFIX = 
ConfigKeys.KEY_FLINK_PROPERTY_PREFIX();
+    private static final String OPTION_PREFIX = 
ConfigKeys.KEY_FLINK_OPTION_PREFIX();
+    private static final String OPTION_MAIN = PROPERTY_PREFIX + 
"$internal.application.main";
+
+    private static final Options FLINK_OPTIONS = FlinkRunOption.allOptions();
+    private static final DefaultParser PARSER = new DefaultParser();
+
+    private ParameterCli() {
+    }
+
+    public static void main(String[] args) {
+        System.out.print(read(args));
+    }
+
+    public static String read(String[] args) {
+        switch (args[0]) {
+            case "--vmopt":
+                ClassLoader classLoader = ClassLoader.getSystemClassLoader();
+                if (classLoader instanceof URLClassLoader) {
+                    return "";
+                }
+                return "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED "
+                    + "--add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED";
+            default:
+                String action = args[0];
+                String conf = args[1];
+                Map<String, String> map;
+                try {
+                    String extension = conf.substring(conf.lastIndexOf('.') + 
1).toLowerCase();
+                    switch (extension) {
+                        case "yml":
+                        case "yaml":
+                            map = PropertiesUtils.fromYamlFile(conf);
+                            break;
+                        case "conf":
+                            map = PropertiesUtils.fromHoconFile(conf);
+                            break;
+                        case "properties":
+                            map = PropertiesUtils.fromPropertiesFile(conf);
+                            break;
+                        default:
+                            throw new IllegalArgumentException(
+                                "[StreamPark] Usage:flink.conf file error,must 
be (yml|conf|properties)");
+                    }
+                } catch (Exception e) {
+                    map = Collections.emptyMap();
+                }
+                String[] programArgs = new String[args.length - 2];
+                System.arraycopy(args, 2, programArgs, 0, programArgs.length);
+                switch (action) {
+                    case "--option":
+                        String[] option = getOption(map, programArgs);
+                        StringBuilder buffer = new StringBuilder();
+                        try {
+                            org.apache.commons.cli.CommandLine line =
+                                PARSER.parse(FLINK_OPTIONS, option, false);
+                            for (org.apache.commons.cli.Option x : 
line.getOptions()) {
+                                buffer.append(" -").append(x.getOpt());
+                                if (x.hasArg()) {
+                                    buffer.append(" ").append(x.getValue());
+                                }
+                            }
+                        } catch (Exception exception) {
+                            exception.printStackTrace();

Review Comment:
   ## SonarCloud / Debugging features should not be enabled in production
   
   <!--SONAR_ISSUE_KEY:AZ8ykYjvPgOMskWIlgLD-->Make sure this debug feature is 
deactivated before delivering the code in production. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_incubator-streampark&issues=AZ8ykYjvPgOMskWIlgLD&open=AZ8ykYjvPgOMskWIlgLD&pullRequest=4418";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/streampark/security/code-scanning/169)



##########
streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/java/org/apache/streampark/flink/core/conf/ParameterCli.java:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.streampark.flink.core.conf;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+import org.apache.streampark.common.util.PropertiesUtils;
+
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Options;
+
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** Parses Flink application CLI parameters from configuration files. */
+public final class ParameterCli {
+
+    private static final String PROPERTY_PREFIX = 
ConfigKeys.KEY_FLINK_PROPERTY_PREFIX();
+    private static final String OPTION_PREFIX = 
ConfigKeys.KEY_FLINK_OPTION_PREFIX();
+    private static final String OPTION_MAIN = PROPERTY_PREFIX + 
"$internal.application.main";
+
+    private static final Options FLINK_OPTIONS = FlinkRunOption.allOptions();
+    private static final DefaultParser PARSER = new DefaultParser();
+
+    private ParameterCli() {
+    }
+
+    public static void main(String[] args) {
+        System.out.print(read(args));
+    }
+
+    public static String read(String[] args) {
+        switch (args[0]) {
+            case "--vmopt":
+                ClassLoader classLoader = ClassLoader.getSystemClassLoader();
+                if (classLoader instanceof URLClassLoader) {
+                    return "";
+                }
+                return "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED "
+                    + "--add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED";
+            default:
+                String action = args[0];
+                String conf = args[1];
+                Map<String, String> map;
+                try {
+                    String extension = conf.substring(conf.lastIndexOf('.') + 
1).toLowerCase();
+                    switch (extension) {
+                        case "yml":
+                        case "yaml":
+                            map = PropertiesUtils.fromYamlFile(conf);
+                            break;
+                        case "conf":
+                            map = PropertiesUtils.fromHoconFile(conf);
+                            break;
+                        case "properties":
+                            map = PropertiesUtils.fromPropertiesFile(conf);
+                            break;
+                        default:
+                            throw new IllegalArgumentException(
+                                "[StreamPark] Usage:flink.conf file error,must 
be (yml|conf|properties)");
+                    }
+                } catch (Exception e) {
+                    map = Collections.emptyMap();
+                }
+                String[] programArgs = new String[args.length - 2];
+                System.arraycopy(args, 2, programArgs, 0, programArgs.length);
+                switch (action) {
+                    case "--option":
+                        String[] option = getOption(map, programArgs);
+                        StringBuilder buffer = new StringBuilder();
+                        try {
+                            org.apache.commons.cli.CommandLine line =
+                                PARSER.parse(FLINK_OPTIONS, option, false);
+                            for (org.apache.commons.cli.Option x : 
line.getOptions()) {
+                                buffer.append(" -").append(x.getOpt());
+                                if (x.hasArg()) {
+                                    buffer.append(" ").append(x.getValue());
+                                }
+                            }
+                        } catch (Exception exception) {
+                            exception.printStackTrace();
+                        }
+                        String mainClass = map.get(OPTION_MAIN);
+                        if (mainClass != null) {
+                            buffer.append(" -c ").append(mainClass);
+                        }
+                        return buffer.toString().trim();
+                    case "--property":
+                        StringBuilder propertyBuffer = new StringBuilder();
+                        for (Map.Entry<String, String> entry : map.entrySet()) 
{
+                            String key = entry.getKey();
+                            String value = entry.getValue();
+                            if (!OPTION_MAIN.equals(key)
+                                && key.startsWith(PROPERTY_PREFIX)
+                                && value != null
+                                && !value.isEmpty()) {
+                                String propertyKey = 
key.substring(PROPERTY_PREFIX.length()).trim();
+                                String propertyValue = value.trim();
+                                if 
(ConfigKeys.KEY_FLINK_APP_NAME().equals(propertyKey)) {
+                                    propertyBuffer
+                                        .append(" -D")
+                                        .append(propertyKey)
+                                        .append("=")
+                                        .append(propertyValue.replace(" ", 
"_"));
+                                } else {
+                                    propertyBuffer
+                                        .append(" -D")
+                                        .append(propertyKey)
+                                        .append("=")
+                                        .append(propertyValue);
+                                }
+                            }
+                        }
+                        return propertyBuffer.toString().trim();
+                    case "--name":
+                        String appName =
+                            map.getOrDefault(
+                                
PROPERTY_PREFIX.concat(ConfigKeys.KEY_FLINK_APP_NAME()), "");
+                        appName = appName.trim();
+                        return appName.isEmpty() ? "" : appName;
+                    case "--detached":
+                        String[] detachedOption = getOption(map, programArgs);
+                        try {
+                            org.apache.commons.cli.CommandLine line =
+                                PARSER.parse(FlinkRunOption.allOptions(), 
detachedOption, false);
+                            boolean detached =
+                                
line.hasOption(FlinkRunOption.DETACHED_OPTION.getOpt())
+                                    || line.hasOption(
+                                        
FlinkRunOption.DETACHED_OPTION.getLongOpt());
+                            return detached ? "Detached" : "Attach";
+                        } catch (Exception e) {
+                            e.printStackTrace();

Review Comment:
   ## SonarCloud / Debugging features should not be enabled in production
   
   <!--SONAR_ISSUE_KEY:AZ8ykYjvPgOMskWIlgLE-->Make sure this debug feature is 
deactivated before delivering the code in production. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_incubator-streampark&issues=AZ8ykYjvPgOMskWIlgLE&open=AZ8ykYjvPgOMskWIlgLE&pullRequest=4418";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/streampark/security/code-scanning/170)



##########
streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/java/org/apache/streampark/flink/core/conf/ParameterCli.java:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.streampark.flink.core.conf;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+import org.apache.streampark.common.util.PropertiesUtils;
+
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Options;
+
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** Parses Flink application CLI parameters from configuration files. */
+public final class ParameterCli {
+
+    private static final String PROPERTY_PREFIX = 
ConfigKeys.KEY_FLINK_PROPERTY_PREFIX();
+    private static final String OPTION_PREFIX = 
ConfigKeys.KEY_FLINK_OPTION_PREFIX();
+    private static final String OPTION_MAIN = PROPERTY_PREFIX + 
"$internal.application.main";
+
+    private static final Options FLINK_OPTIONS = FlinkRunOption.allOptions();
+    private static final DefaultParser PARSER = new DefaultParser();
+
+    private ParameterCli() {
+    }
+
+    public static void main(String[] args) {
+        System.out.print(read(args));
+    }
+
+    public static String read(String[] args) {
+        switch (args[0]) {
+            case "--vmopt":
+                ClassLoader classLoader = ClassLoader.getSystemClassLoader();
+                if (classLoader instanceof URLClassLoader) {
+                    return "";
+                }
+                return "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED "
+                    + "--add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED";
+            default:
+                String action = args[0];
+                String conf = args[1];
+                Map<String, String> map;
+                try {
+                    String extension = conf.substring(conf.lastIndexOf('.') + 
1).toLowerCase();
+                    switch (extension) {
+                        case "yml":
+                        case "yaml":
+                            map = PropertiesUtils.fromYamlFile(conf);
+                            break;
+                        case "conf":
+                            map = PropertiesUtils.fromHoconFile(conf);
+                            break;
+                        case "properties":
+                            map = PropertiesUtils.fromPropertiesFile(conf);
+                            break;
+                        default:
+                            throw new IllegalArgumentException(
+                                "[StreamPark] Usage:flink.conf file error,must 
be (yml|conf|properties)");
+                    }
+                } catch (Exception e) {
+                    map = Collections.emptyMap();
+                }
+                String[] programArgs = new String[args.length - 2];
+                System.arraycopy(args, 2, programArgs, 0, programArgs.length);
+                switch (action) {
+                    case "--option":
+                        String[] option = getOption(map, programArgs);
+                        StringBuilder buffer = new StringBuilder();
+                        try {
+                            org.apache.commons.cli.CommandLine line =
+                                PARSER.parse(FLINK_OPTIONS, option, false);
+                            for (org.apache.commons.cli.Option x : 
line.getOptions()) {
+                                buffer.append(" -").append(x.getOpt());
+                                if (x.hasArg()) {
+                                    buffer.append(" ").append(x.getValue());
+                                }
+                            }
+                        } catch (Exception exception) {
+                            exception.printStackTrace();
+                        }
+                        String mainClass = map.get(OPTION_MAIN);
+                        if (mainClass != null) {
+                            buffer.append(" -c ").append(mainClass);
+                        }
+                        return buffer.toString().trim();
+                    case "--property":
+                        StringBuilder propertyBuffer = new StringBuilder();
+                        for (Map.Entry<String, String> entry : map.entrySet()) 
{
+                            String key = entry.getKey();
+                            String value = entry.getValue();
+                            if (!OPTION_MAIN.equals(key)
+                                && key.startsWith(PROPERTY_PREFIX)
+                                && value != null
+                                && !value.isEmpty()) {
+                                String propertyKey = 
key.substring(PROPERTY_PREFIX.length()).trim();
+                                String propertyValue = value.trim();
+                                if 
(ConfigKeys.KEY_FLINK_APP_NAME().equals(propertyKey)) {
+                                    propertyBuffer
+                                        .append(" -D")
+                                        .append(propertyKey)
+                                        .append("=")
+                                        .append(propertyValue.replace(" ", 
"_"));
+                                } else {
+                                    propertyBuffer
+                                        .append(" -D")
+                                        .append(propertyKey)
+                                        .append("=")
+                                        .append(propertyValue);
+                                }
+                            }
+                        }
+                        return propertyBuffer.toString().trim();
+                    case "--name":
+                        String appName =
+                            map.getOrDefault(
+                                
PROPERTY_PREFIX.concat(ConfigKeys.KEY_FLINK_APP_NAME()), "");
+                        appName = appName.trim();
+                        return appName.isEmpty() ? "" : appName;
+                    case "--detached":
+                        String[] detachedOption = getOption(map, programArgs);
+                        try {
+                            org.apache.commons.cli.CommandLine line =
+                                PARSER.parse(FlinkRunOption.allOptions(), 
detachedOption, false);
+                            boolean detached =
+                                
line.hasOption(FlinkRunOption.DETACHED_OPTION.getOpt())
+                                    || line.hasOption(
+                                        
FlinkRunOption.DETACHED_OPTION.getLongOpt());
+                            return detached ? "Detached" : "Attach";
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            return "Attach";
+                        }
+                    default:
+                        return null;
+                }
+        }
+    }
+
+    public static String[] getOption(Map<String, String> map, String[] args) {
+        Map<String, Object> optionMap = new HashMap<>();
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            String key = entry.getKey();
+            String value = entry.getValue();
+            if (key.startsWith(OPTION_PREFIX) && value != null && 
!value.isEmpty()) {
+                String optionKey = key.substring(OPTION_PREFIX.length());
+                if (FLINK_OPTIONS.hasOption(optionKey)) {
+                    Object parsedValue;
+                    if ("true".equalsIgnoreCase(value) || 
"false".equalsIgnoreCase(value)) {
+                        parsedValue = Boolean.parseBoolean(value);
+                    } else {
+                        parsedValue = value;
+                    }
+                    if (parsedValue instanceof Boolean) {
+                        if ((Boolean) parsedValue) {
+                            optionMap.put("-" + optionKey.trim(), true);
+                        }
+                    } else {
+                        optionMap.put("-" + optionKey.trim(), parsedValue);
+                    }
+                }
+            }
+        }
+        if (args.length > 0) {
+            try {
+                org.apache.commons.cli.CommandLine line = 
PARSER.parse(FLINK_OPTIONS, args, false);
+                for (org.apache.commons.cli.Option x : line.getOptions()) {
+                    if (x.hasArg()) {
+                        optionMap.put("-" + x.getLongOpt().trim(), 
x.getValue());
+                    } else {
+                        optionMap.put("-" + x.getLongOpt().trim(), true);
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();

Review Comment:
   ## SonarCloud / Debugging features should not be enabled in production
   
   <!--SONAR_ISSUE_KEY:AZ8ykYjvPgOMskWIlgLG-->Make sure this debug feature is 
deactivated before delivering the code in production. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_incubator-streampark&issues=AZ8ykYjvPgOMskWIlgLG&open=AZ8ykYjvPgOMskWIlgLG&pullRequest=4418";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/streampark/security/code-scanning/171)



##########
streampark-flink/streampark-flink-connector/streampark-flink-connector-clickhouse/src/main/java/org/apache/streampark/flink/connector/clickhouse/internal/ClickHouseSinkFunction.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.streampark.flink.connector.clickhouse.internal;
+
+import org.apache.streampark.common.util.JdbcUtils;
+import 
org.apache.streampark.flink.connector.clickhouse.conf.ClickHouseJdbcConfig;
+import 
org.apache.streampark.flink.connector.clickhouse.util.ClickhouseConvertUtils;
+import org.apache.streampark.flink.connector.function.TransformFunction;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.slf4j.Logger; import org.slf4j.LoggerFactory;
+import ru.yandex.clickhouse.ClickHouseDataSource;
+import ru.yandex.clickhouse.settings.ClickHouseProperties;
+import java.lang.reflect.Field;
+import java.sql.Connection; import java.sql.Statement;
+import java.util.ArrayList; import java.util.List; import java.util.Map;
+import java.util.Properties; import java.util.concurrent.atomic.AtomicLong;
+
+public class ClickHouseSinkFunction<T> extends RichSinkFunction<T> {
+    private static final Logger LOG = 
LoggerFactory.getLogger(ClickHouseSinkFunction.class);
+    private Connection connection; private Statement statement;
+    private final ClickHouseJdbcConfig clickHouseConf;
+    private final int batchSize; private final AtomicLong offset = new 
AtomicLong(0L);
+    private long timestamp = 0L; private final long flushInterval;
+    private final List<String> sqlValues = new ArrayList<>();
+    private String insertSqlPrefixes;
+    private final TransformFunction<T, String> sqlFunc;
+
+    public ClickHouseSinkFunction(Properties properties, TransformFunction<T, 
String> sqlFunc) {
+        this.clickHouseConf = new ClickHouseJdbcConfig(properties);
+        this.batchSize = clickHouseConf.batchSize;
+        this.flushInterval = clickHouseConf.flushInterval;
+        this.sqlFunc = sqlFunc;
+    }
+
+    @Override public void open(Configuration parameters) throws Exception {
+        String user = clickHouseConf.user; String driver = 
clickHouseConf.driverClassName;
+        ClickHouseProperties chProps = new ClickHouseProperties();
+        if (user != null && driver != null) { Class.forName(driver); 
chProps.setUser(user); }
+        else if (driver != null) Class.forName(driver);
+        else if (user != null) chProps.setUser(user);
+        for (Map.Entry<Object,Object> x : 
clickHouseConf.sinkOption.getInternalConfig().entrySet()) {
+            try {
+                Field field = 
chProps.getClass().getDeclaredField(x.getKey().toString());
+                field.setAccessible(true);
+                String tn = field.getType().getSimpleName();
+                if ("String".equals(tn)) field.set(chProps, x.getValue());
+                else if ("int".equals(tn) || "Integer".equals(tn)) 
field.set(chProps, Integer.parseInt(x.getValue().toString()));
+                else if ("long".equals(tn) || "Long".equals(tn)) 
field.set(chProps, Long.parseLong(x.getValue().toString()));
+                else if ("boolean".equals(tn) || "Boolean".equals(tn)) 
field.set(chProps, Boolean.parseBoolean(x.getValue().toString()));
+            } catch (NoSuchFieldException e) {
+                LOG.warn("ClickHouseProperties config error, property:{} 
invalid", x.getKey());
+            }
+        }
+        connection = new ClickHouseDataSource(clickHouseConf.jdbcUrl, 
chProps).getConnection();
+    }
+
+    @Override public void invoke(T value, SinkFunction.Context context) throws 
Exception {
+        String sql = sqlFunc != null ? sqlFunc.transform(value) : 
ClickhouseConvertUtils.convert(value);
+        if (batchSize == 1) {
+            connection.prepareStatement(sql).executeUpdate();
+        } else {
+            sqlValues.add(sql);
+            long cnt = offset.incrementAndGet();
+            long now = System.currentTimeMillis();
+            if (cnt % batchSize == 0 || now - timestamp > flushInterval) 
execBatch();
+        }
+    }
+
+    @Override public void close() throws Exception { execBatch(); 
JdbcUtils.close(statement, connection); }
+
+    private void execBatch() throws Exception {
+        if (offset.get() > 0) {
+            try {
+                LOG.info("ClickHouseSink batch {} insert begin..", 
offset.get());
+                offset.set(0);
+                String valuesStr = String.join(",", sqlValues);
+                connection.prepareStatement(insertSqlPrefixes + " " + 
valuesStr).executeUpdate();

Review Comment:
   ## SonarCloud / SQL queries should not be dynamically formatted
   
   <!--SONAR_ISSUE_KEY:AZ8ykYeLPgOMskWIlgJC-->Make sure using a dynamically 
formatted SQL query is safe here. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_incubator-streampark&issues=AZ8ykYeLPgOMskWIlgJC&open=AZ8ykYeLPgOMskWIlgJC&pullRequest=4418";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/streampark/security/code-scanning/168)



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