feat: add LPAD/RPAD string functions - #178
Open
jadhavgaurav wants to merge 1 commit into
Open
jadhavgaurav wants to merge 1 commit into
jadhavgaurav wants to merge 1 commit into
Conversation
Adds LPAD(col, len[, pad]) and RPAD(col, len[, pad]) to the scalar function set in src/scalar.zig, mirroring SUBSTR's parsing/eval pattern: a dedicated args struct, a parse block that resolves the column and splits the remaining comma-separated args, and an eval branch per direction. pad defaults to a single space when the third argument is omitted. A value already at or past the target length, or an explicit empty pad string, is left unchanged rather than truncated. Fixes melihbirim#160.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
LPAD(col, len[, pad])andRPAD(col, len[, pad])to the scalar function set insrc/scalar.zig, following the pattern the issue points at (SUBSTR): a dedicated args struct, a parse block that resolves the column and splits the remaining comma-separated arguments, and an eval branch per direction.Behavior
paddefaults to a single space when the third argument is omitted, matching common SQL dialects.padrepeats/wraps to fill the remaining width.padstring (LPAD(col, n, '')) is also a no-op when padding would otherwise be needed, since there's nothing to repeat.Tests
src/scalar.zig: unit tests covering basic pad-left/pad-right, the omitted-third-arg default, a multi-character pad, the already-at-or-past-length no-op (both exact-length and longer), and the empty-pad no-op.src/engine.zig: one end-to-end test runningSELECT LPAD(...), RPAD(...) FROM '<file>'through the full query pipeline..lpad/.rpadeval to a passthrough — the relevant tests failed as expected, then passed again once reverted.Docs
Added
LPAD/RPADto the SQL Reference table inSQL_REFERENCE.md, the function list inREADME.md, and a Roadmap row referencing #160.Checks
zig build(Debug and ReleaseFast) — cleanzig build test— 632/632 passedzig fmt --check src/ tests/ build.zig— cleanFixes #160.