Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve][Core] Config variables update doc and add test case #7709

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/en/concept/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions docs/zh/concept/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
Expand All @@ -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<? extends ConfigObject> transformConfigs = config.getObjectList("transform");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ source {
schema = {
fields {
name = "${nameType:string}"
age = ${ageType}
age = "${ageType}"
}
}
}
Expand Down
Loading