diff --git a/docs/en/concept/config.md b/docs/en/concept/config.md index 0713c1974e8..cec01dc0d8f 100644 --- a/docs/en/concept/config.md +++ b/docs/en/concept/config.md @@ -221,10 +221,8 @@ export varName="value with space" ``` Then you can use the variable in the config file. -If you set a variable without default value in the config file but do not pass it during execution, an exception will be thrown. Example: -```shell -Caused by: org.apache.seatunnel.core.starter.exception.CommandExecuteException: Variable substitution error: ${resName}_table -``` +If you set a variable without a default value in the configuration file but do not pass it during execution, the value of the variable will be retained and the system will not throw an exception. But please ensure that other processes can correctly parse the variable value. For example, ElasticSearch's index needs to support a format like '${xxx}' to dynamically specify the index. If other processes are not supported, the program may not run properly. + ### Example: ```hocon diff --git a/docs/zh/concept/config.md b/docs/zh/concept/config.md index e94818aa33c..2206441e801 100644 --- a/docs/zh/concept/config.md +++ b/docs/zh/concept/config.md @@ -206,11 +206,7 @@ export varName="value with space" ``` 然后您可以在配置文件中使用变量。 -如果您在配置文件中设置了没有默认值的变量,但在执行中未传递,则会抛出异常。 -如: -```shell -Caused by: org.apache.seatunnel.core.starter.exception.CommandExecuteException: Variable substitution error: ${resName}_table -``` +如果您在配置文件中设置了没有默认值的变量,但在执行过程中未传递该变量,则会保留该变量值,系统不会抛出异常。但请您需要确保其他流程能够正确解析该变量值。例如,ElasticSearch的索引需要支持`${xxx}`这样的格式来动态指定索引。若其他流程不支持,程序可能无法正常运行。 具体样例: ```hocon diff --git a/seatunnel-core/seatunnel-core-starter/src/test/java/org/apache/seatunnel/core/starter/utils/ConfigShadeTest.java b/seatunnel-core/seatunnel-core-starter/src/test/java/org/apache/seatunnel/core/starter/utils/ConfigShadeTest.java index b91b144d45c..fb3fd85f63a 100644 --- a/seatunnel-core/seatunnel-core-starter/src/test/java/org/apache/seatunnel/core/starter/utils/ConfigShadeTest.java +++ b/seatunnel-core/seatunnel-core-starter/src/test/java/org/apache/seatunnel/core/starter/utils/ConfigShadeTest.java @@ -190,12 +190,10 @@ public void testVariableReplacement() throws URISyntaxException { public void testVariableReplacementWithDefaultValue() throws URISyntaxException { String jobName = "seatunnel variable test job"; Assertions.assertEquals(System.getenv("jobName"), jobName); - String ageType = "int"; String sourceTableName = "sql"; String containSpaceString = "f h"; List variables = new ArrayList<>(); variables.add("strTemplate=[abc,de~," + containSpaceString + "]"); - variables.add("ageType=" + ageType); // Set the environment variable value nameVal to `f h` to verify whether setting the space // through the environment variable is effective System.setProperty("nameValForEnv", containSpaceString); @@ -214,6 +212,10 @@ public void testVariableReplacementWithDefaultValue() throws URISyntaxException Assertions.assertEquals(list1.get(1), "de~"); Assertions.assertEquals(list1.get(2), containSpaceString); Assertions.assertEquals(sourceConfig.getInt("row.num"), 50); + // Verify when verifying without setting variables, ${xxx} should be retained + Assertions.assertEquals( + sourceConfig.getConfig("schema").getConfig("fields").getString("age"), + "${ageType}"); Assertions.assertEquals(sourceConfig.getString("result_table_name"), "fake_test_table"); } List transformConfigs = config.getObjectList("transform"); diff --git a/seatunnel-core/seatunnel-core-starter/src/test/resources/config_variables_with_default_value.conf b/seatunnel-core/seatunnel-core-starter/src/test/resources/config_variables_with_default_value.conf index 1bdde33ac0b..23f7293f566 100644 --- a/seatunnel-core/seatunnel-core-starter/src/test/resources/config_variables_with_default_value.conf +++ b/seatunnel-core/seatunnel-core-starter/src/test/resources/config_variables_with_default_value.conf @@ -30,7 +30,7 @@ source { schema = { fields { name = "${nameType:string}" - age = ${ageType} + age = "${ageType}" } } }