lsyldliu commented on code in PR #25127:
URL: https://github.com/apache/flink/pull/25127#discussion_r1696908937
##########
docs/data/sql_functions.yml:
##########
@@ -274,6 +274,12 @@ string:
- sql: RTRIM(string)
table: STRING.rtrim()
description: Returns a string that removes the right whitespaces from
STRING. E.g., 'This is a test String. '.rtrim() returns "This is a test
String.".
+ - sql: BTRIM(str[, trimStr])
+ table: str.btrim([trimStr])
+ description: |
+ Removes any leading and trailing characters within trimStr from str.
trimStr is set to a space character by default.
+ str <CHAR | VARCHAR>[, trimStr <CHAR | VARCHAR>]
Review Comment:
```suggestion
str <CHAR | VARCHAR>
trimStr <CHAR | VARCHAR>
```
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/StringFunctionsITCase.java:
##########
@@ -46,4 +51,70 @@ Stream<TestSetSpec> getTestSetSpecs() {
"ABC",
DataTypes.STRING().nullable()));
}
+
+ private Stream<TestSetSpec> bTrimTestCases() {
+ return Stream.of(
+ TestSetSpec.forFunction(BuiltInFunctionDefinitions.BTRIM)
+ .onFieldsWithData(null, " \uD83D\uDE00www.apache.org
\f ")
+ .andDataTypes(DataTypes.STRING(), DataTypes.STRING())
+ // null input
+ .testResult($("f0").btrim(), "BTRIM(f0)", null,
DataTypes.STRING())
+ .testResult(
+ $("f0").btrim($("f1")), "BTRIM(f0, f1)", null,
DataTypes.STRING())
+ .testResult(
+ $("f1").btrim($("f0")), "BTRIM(f1, f0)", null,
DataTypes.STRING())
+ // special chars
+ .testResult(
+ $("f1").btrim(" \f\uD83D\uDE00"),
+ "BTRIM(f1, ' \f\uD83D\uDE00')",
+ "www.apache.org",
+ DataTypes.STRING())
+ .testResult(
+ $("f1").btrim("\uD83D\uDE00 "),
+ "BTRIM(f1, '\uD83D\uDE00 ')",
+ "www.apache.org \f",
+ DataTypes.STRING())
+ // return type
+ .testResult(
+ lit(" www.apache.org ").btrim(),
+ "BTRIM(' www.apache.org ')",
+ "www.apache.org",
+ DataTypes.STRING().notNull())
+ // normal cases
+ .testResult(
+ $("f1").btrim(),
+ "BTRIM(f1)",
+ "\uD83D\uDE00www.apache.org \f",
+ DataTypes.STRING())
+ .testResult(
+ $("f1").btrim("\f"),
+ "BTRIM(f1, '\f')",
+ " \uD83D\uDE00www.apache.org \f ",
Review Comment:
Can you also a normal test case: btrim(f1, 'a');
##########
docs/data/sql_functions_zh.yml:
##########
@@ -340,6 +340,12 @@ string:
description: |
返回从 STRING 中删除右边空格的字符串。
例如 `'This is a test String. '.rtrim()` 返回 `'This is a test String.'`。
+ - sql: BTRIM(str[, trimStr])
+ table: str.btrim([trimStr])
+ description: |
+ 从 str 的前缀和后缀字符中裁去 trimStr 中的字符。trimStr 默认设置为空格。
Review Comment:
前缀 -> 左边;后缀 -> 右边。
裁剪 -> 删除
--
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]