Skip to content

feat: add LPAD/RPAD string functions - #178

Open
jadhavgaurav wants to merge 1 commit into
melihbirim:mainfrom
jadhavgaurav:feat/lpad-rpad
Open

jadhavgaurav wants to merge 1 commit into
melihbirim:mainfrom
jadhavgaurav:feat/lpad-rpad

Conversation

@jadhavgaurav

Copy link
Copy Markdown

Adds LPAD(col, len[, pad]) and RPAD(col, len[, pad]) to the scalar function set in src/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

  • pad defaults to a single space when the third argument is omitted, matching common SQL dialects.
  • A multi-character pad repeats/wraps to fill the remaining width.
  • A value already at or past the target length is returned unchanged (no truncation).
  • An explicit empty pad string (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 running SELECT LPAD(...), RPAD(...) FROM '<file>' through the full query pipeline.
  • Verified these tests actually exercise the new code by temporarily stubbing .lpad/.rpad eval to a passthrough — the relevant tests failed as expected, then passed again once reverted.

Docs

Added LPAD/RPAD to the SQL Reference table in SQL_REFERENCE.md, the function list in README.md, and a Roadmap row referencing #160.

Checks

  • zig build (Debug and ReleaseFast) — clean
  • zig build test — 632/632 passed
  • zig fmt --check src/ tests/ build.zig — clean

Fixes #160.

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.
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 LPAD / RPAD string functions

1 participant