Right-pads each string by truncating or padding with the character.
Returns:
| Name | Type | Description |
Expression | Expression | a String expression which is self truncated or right-padded with the pad character |
Note
If the string is longer than the specified length, it will be truncated. The pad character must be a single character.
Examples:
| >>> import daft
>>> from daft.functions import rpad
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(rpad(df["x"], 6, "0"))
>>> df.show()
|
╭────────╮
│ x │
│ --- │
│ String │
╞════════╡
│ daft00 │
├╌╌╌╌╌╌╌╌┤
│ query0 │
├╌╌╌╌╌╌╌╌┤
│ engine │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664 | def rpad(expr: Expression, length: int | Expression, pad: str | Expression) -> Expression:
"""Right-pads each string by truncating or padding with the character.
Returns:
Expression: a String expression which is `self` truncated or right-padded with the pad character
Note:
If the string is longer than the specified length, it will be truncated.
The pad character must be a single character.
Examples:
>>> import daft
>>> from daft.functions import rpad
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(rpad(df["x"], 6, "0"))
>>> df.show()
╭────────╮
│ x │
│ --- │
│ String │
╞════════╡
│ daft00 │
├╌╌╌╌╌╌╌╌┤
│ query0 │
├╌╌╌╌╌╌╌╌┤
│ engine │
╰────────╯
<BLANKLINE>
(Showing first 3 of 3 rows)
"""
return Expression._call_builtin_scalar_fn("rpad", expr, length, pad)
|