Skip to content

Commit

Permalink
[FLINK-36896][table] Table API trim() expression incorrectly transl…
Browse files Browse the repository at this point in the history
…ated to SQL
  • Loading branch information
snuyanzin authored Dec 12, 2024
1 parent 1580b4d commit 72b32fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ public static Stream<TestSpec> testData() {
.expectStr("POSITION(`f0` IN 'ABC')"),
TestSpec.forExpr($("f0").trim("ABC"))
.withField("f0", DataTypes.STRING())
.expectStr("TRIM BOTH 'ABC' FROM `f0`"),
.expectStr("TRIM(BOTH 'ABC' FROM `f0`)"),
TestSpec.forExpr($("f0").trimLeading("ABC"))
.withField("f0", DataTypes.STRING())
.expectStr("TRIM LEADING 'ABC' FROM `f0`"),
.expectStr("TRIM(LEADING 'ABC' FROM `f0`)"),
TestSpec.forExpr($("f0").trimTrailing("ABC"))
.withField("f0", DataTypes.STRING())
.expectStr("TRIM TRAILING 'ABC' FROM `f0`"),
.expectStr("TRIM(TRAILING 'ABC' FROM `f0`)"),
TestSpec.forExpr($("f0").overlay("ABC", 2))
.withField("f0", DataTypes.STRING())
.expectStr("OVERLAY(`f0` PLACING 'ABC' FROM 2)"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ private String doUnParse(

// leading & trailing is translated to BOTH
if (trimLeading && trimTrailing) {
format = "TRIM BOTH %s FROM %s";
format = "TRIM(BOTH %s FROM %s)";
} else if (trimLeading) {
format = "TRIM LEADING %s FROM %s";
format = "TRIM(LEADING %s FROM %s)";
} else if (trimTrailing) {
format = "TRIM TRAILING %s FROM %s";
format = "TRIM(TRAILING %s FROM %s)";
} else {
format = "TRIM %s FROM %s";
format = "TRIM(%s FROM %s)";
}

return String.format(
Expand Down

0 comments on commit 72b32fc

Please sign in to comment.