String Functions
25 functions for trimming, casing, padding, and character-level string manipulation. The source column is always the implicit first input.
| Function | Syntax | Parameters | Notes |
|---|---|---|---|
trim | trim(column) | None. | Removes leading and trailing whitespace. |
ltrim | ltrim(column) | None. | Removes leading whitespace only. |
rtrim | rtrim(column) | None. | Removes trailing whitespace only. |
upper | upper(column) | None. | Converts to uppercase. |
lower | lower(column) | None. | Converts to lowercase. |
title_case | title_case(column) | None. | Capitalizes the first letter of each word (Spark initcap). |
length | length(column) | None. | Returns character length. |
concat | concat(column, values[]) | values — array of operands, each {mode: "column"|"literal"|"expression", value}. | Concatenates the source column with each operand in order. Legacy single-value/suffix form also supported. |
substring | substring(column, startPos, length) | startPos default 1. length default 1. | 1-indexed, matches Spark substring() semantics. |
pad_left | pad_left(column, length, padChar) | length default 10. padChar default "0". | F.lpad(). |
pad_right | pad_right(column, length, padChar) | length default 10. padChar default " ". | F.rpad(). |
replace | replace(column, search, replace) | search, replace — literal substrings. | Plain substring replace, not regex (see Regex category for pattern-based replace). |
reverse | reverse(column) | None. | Reverses character order. |
concat_ws | concat_ws(column, separator, values[]) | separator default ",". values — array of operands. | Concatenate-with-separator; nulls are skipped. |
left | left(column, length) | length default 1. | Leftmost N characters. |
right | right(column, length) | length default 1. | Rightmost N characters. |
position | position(column, search) | search — substring to locate. | Returns 1-indexed position, 0 if not found. |
char_length | char_length(column) | None. | Character count (alias of length for character semantics). |
octet_length | octet_length(column) | None. | Byte length. |
bit_length | bit_length(column) | None. | Bit length (octet_length * 8). |
translate | translate(column, fromChars, toChars) | fromChars, toChars — matched character sets. | Character-by-character substitution, F.translate(). |
repeat | repeat(column, count) | count default 2. | |
ascii_code | ascii_code(column) | None. | ASCII code of the first character. |
char_from_code | char_from_code(column) | None. | CHR(CAST(column AS INT)) — inverse of ascii_code. |
soundex_difference | soundex_difference(column, otherColumn) | otherColumn — column to compare against. | Compares Soundex codes of the two columns; returns a boolean/difference indicator. |