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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799 | 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)
|