snowflake.snowpark.functions.translate¶
- snowflake.snowpark.functions.translate(src: Union[Column, str], source_alphabet: Union[Column, str], target_alphabet: Union[Column, str]) Column [source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L2900-L2924)¶
Translates src from the characters in source_alphabet to the characters in target_alphabet. Each character matching a character at position i in the source_alphabet is replaced with the character at position i in the target_alphabet. If target_alphabet is shorter, and there is no corresponding character the character is omitted. target_alphabet can not be longer than source_alphabet.
Example:
>>> df = session.create_dataframe(["abcdef", "abba"], schema=["a"]) >>> df.select(translate(col("a"), lit("abc"), lit("ABC")).as_("ans")).collect() [Row(ANS='ABCdef'), Row(ANS='ABBA')] >>> df = session.create_dataframe(["file with spaces.txt", "\ttest"], schema=["a"]) >>> df.select(translate(col("a"), lit(" \t"), lit("_")).as_("ans")).collect() [Row(ANS='file_with_spaces.txt'), Row(ANS='test')]