Skip to content

[ISSUE-789] Add TRIM, LPAD, and RPAD string functions - #826

Open
914zzzz wants to merge 2 commits into
apache:masterfrom
914zzzz:codex/issue-789-string-functions
Open

[ISSUE-789] Add TRIM, LPAD, and RPAD string functions#826
914zzzz wants to merge 2 commits into
apache:masterfrom
914zzzz:codex/issue-789-string-functions

Conversation

@914zzzz

@914zzzz 914zzzz commented Aug 3, 2026

Copy link
Copy Markdown

Closes #789.

What changed

  • Adds and registers LPAD and RPAD with String and BinaryString overloads.
  • Uses Unicode code-point lengths for truncation and padding.
  • Keeps the existing Calcite TRIM operator instead of registering a duplicate UDF.
  • Adds unit and runtime SQL coverage for TRIM, LPAD, and RPAD.
  • Fixes the failing runtime test by using the repository's actual ascii2str(int) function name instead of the nonexistent ascii2string(int) signature.

MySQL behavior comparison

Case Result
Any argument is NULL NULL
Target length is negative NULL
Target length is zero empty string
Target length is shorter than the input input truncated by characters
Pad string is empty and padding is needed original input
Multibyte/emoji input counted by Unicode code point

Verification

  • JDK 8: mvn -B -e -Pjdk8 -Dtest=PadTest,TrimTest -Dmaven.javadoc.skip=true install - 5 tests passed; Checkstyle and RAT passed.
  • JDK 11: mvn -B -e clean test -Pjdk11 -Dtest=PadTest,TrimTest - clean compilation of 250 main and 47 test sources; 5 tests passed; Checkstyle and RAT passed.
  • The corrected TRIM SQL query passes Calcite planning locally. Full runtime execution is covered by the Linux CI because the local Windows BRPC shutdown selects a VPN adapter address.

@914zzzz

914zzzz commented Aug 3, 2026

Copy link
Copy Markdown
Author

#789

@mingcheng

Copy link
Copy Markdown
Member

Please check and fix the CI status before merging.

@914zzzz 914zzzz closed this Aug 5, 2026
@914zzzz 914zzzz reopened this Aug 5, 2026
@914zzzz

914zzzz commented Aug 5, 2026

Copy link
Copy Markdown
Author

I rechecked both failed CI runs and found the actual cause: the new TRIM runtime test called ascii2string(9), but GeaFlow registers this function as ascii2str(int). Both JDK 8 and JDK 11 therefore failed during Calcite function resolution before TRIM executed.

Commit abd591a7 corrects the SQL test. I also removed the duplicate TRIM UDF registration because GeaFlow already supports TRIM through SqlStdOperatorTable.TRIM, and aligned negative LPAD/RPAD lengths with MySQL by returning NULL.

Local verification:

  • JDK 8: PadTest/TrimTest, 5 tests passed; Checkstyle and RAT passed.
  • JDK 11: clean compile of 250 main and 47 test sources; 5 tests passed; Checkstyle and RAT passed.

The new upstream runs are waiting for maintainer approval (they are action_required, not test failures):

Please approve these workflow runs when convenient. After they complete, the PR will still require one approving review from a reviewer with write access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the string functions TRIM / LPAD / RPAD

3 participants