public static String expandListParameter()

in dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ParameterUtils.java [189:246]


    public static String expandListParameter(Map<Integer, Property> params, String sql) {
        Map<Integer, Property> expandMap = new HashMap<>();
        if (params == null || params.isEmpty()) {
            return sql;
        }
        StringBuilder ret = new StringBuilder(sql);
        Matcher m = TaskConstants.SQL_PARAMS_PATTERN.matcher(sql);
        int index = 1;
        int paramsIndex = 1;
        // When matching with a regex, determine whether the corresponding property is a list.
        while (m.find()) {
            Property property = params.get(paramsIndex++);
            if (property == null) {
                continue;
            }
            String value = property.getValue();
            StringBuilder tempReplace = new StringBuilder();
            if (DataType.LIST.equals(property.getType())) {
                List<Object> valueList = JSONUtils.toList(value, Object.class);
                if (valueList.isEmpty() && StringUtils.isNotBlank(value)) {
                    valueList.add(value);
                }
                for (int j = 0; j < valueList.size(); j++) {
                    tempReplace.append(PARAM_REPLACE_CHAR);
                    if (j != valueList.size() - 1) {
                        tempReplace.append(",");
                    }
                }
                for (Object v : valueList) {
                    Property newProperty = new Property();
                    if (v instanceof Integer) {
                        newProperty.setType(DataType.INTEGER);
                    } else if (v instanceof Long) {
                        newProperty.setType(DataType.LONG);
                    } else if (v instanceof Float) {
                        newProperty.setType(DataType.FLOAT);
                    } else if (v instanceof Double) {
                        newProperty.setType(DataType.DOUBLE);
                    } else {
                        newProperty.setType(DataType.VARCHAR);
                    }
                    newProperty.setValue(v.toString());
                    newProperty.setProp(property.getProp());
                    newProperty.setDirect(property.getDirect());
                    expandMap.put(index++, newProperty);
                }
            } else {
                tempReplace.append(PARAM_REPLACE_CHAR);
                expandMap.put(index++, property);
            }
            ret.replace(m.start(), m.end(), tempReplace.toString());
            // After replacement, the string length will change, so a reset is required
            m.reset(ret.toString());
        }
        params.clear();
        params.putAll(expandMap);
        return ret.toString();
    }