You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@streampark.apache.org by GitBox <gi...@apache.org> on 2022/10/21 12:39:48 UTC

[GitHub] [incubator-streampark] 1996fanrui commented on a diff in pull request #1866: [Feature] Reference variables as placeholders in program args and Flink SQL

1996fanrui commented on code in PR #1866:
URL: https://github.com/apache/incubator-streampark/pull/1866#discussion_r1001722386


##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/Variable.java:
##########
@@ -42,7 +42,6 @@ public class Variable implements Serializable {
     private String variableCode;
 
     @NotBlank(message = "{required}")
-    @Size(max = 50, message = "{noMoreThan}")

Review Comment:
   Why delete this code?



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java:
##########
@@ -17,48 +17,79 @@
 
 package org.apache.streampark.console.core.service.impl;
 
+import org.apache.streampark.common.util.DeflaterUtils;
 import org.apache.streampark.console.base.domain.RestRequest;
 import org.apache.streampark.console.base.exception.ApiAlertException;
 import org.apache.streampark.console.base.mybatis.pager.MybatisPager;
+import org.apache.streampark.console.core.entity.Application;
+import org.apache.streampark.console.core.entity.FlinkSql;
 import org.apache.streampark.console.core.entity.Variable;
 import org.apache.streampark.console.core.mapper.VariableMapper;
 import org.apache.streampark.console.core.service.ApplicationService;
 import org.apache.streampark.console.core.service.CommonService;
+import org.apache.streampark.console.core.service.FlinkSqlService;
 import org.apache.streampark.console.core.service.VariableService;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
 public class VariableServiceImpl extends ServiceImpl<VariableMapper, Variable> implements VariableService {
 
+    private final Pattern placeholderPattern = Pattern.compile("\\$\\{([A-Za-z])+([A-Za-z0-9._-])+\\}");

Review Comment:
   If `placeholderStart` and `placeholderEnd ` can be configured, the placeholderPattern should be dynamic.
   
   And I'm afraid, there may be bugs here. 
   
   Hi @macksonmu @wolfboys , I don't recommend supporting configuration `placeholder.start` and `placeholder.end`. Because:
   
   - If placeholderStart is `a`, and `placeholderEnd` is `b`, it’s very easy to conflict.
   - It will also become harder if we want to automatically search for variables when we type $ in the future.
   
   



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java:
##########
@@ -79,4 +110,74 @@ public Variable findByVariableCode(Long teamId, String variableCode) {
     public List<Variable> findByTeamId(Long teamId) {
         return baseMapper.selectByTeamId(teamId);
     }
+
+    /**
+     * Replace placeholders with defined variable codes.
+     * @param teamId
+     * @param paramWithPlaceholders Parameters with placeholders, e.g. "--cluster ${kafka.cluster}"
+     * @return
+     */
+    @Override
+    public String parseVariable(Long teamId, String paramWithPlaceholders) {

Review Comment:
   How about rename to `replaceVariable`?
   
   Your comment is clear: `Replace placeholders with defined variable codes.`
   
   And I don't think `paramWithPlaceholders` is a good name. What does `param` mean here? Is methodParam? Or do you think `sql` or `job args` are param? 



-- 
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: issues-unsubscribe@streampark.apache.org

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