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

@914zzzz914zzzz 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

CaseResult
Any argument is NULLNULL
Target length is negativeNULL
Target length is zeroempty string
Target length is shorter than the inputinput truncated by characters
Pad string is empty and padding is neededoriginal input
Multibyte/emoji inputcounted 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

Copy link
Copy Markdown
Author

#789

@mingcheng

Copy link
Copy Markdown
Member

Please check and fix the CI status before merging.

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

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.

@kitalkuyo-gitakitalkuyo-gita left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for freeto 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

4 participants

@914zzzz@mingcheng@kitalkuyo-gita@914zzq