pyspark.sql.functions.try_validate_utf8#
- pyspark.sql.functions.try_validate_utf8(str)[source]#
Returns the input value if it corresponds to a valid UTF-8 string, or NULL otherwise.
New in version 4.0.0.
- Parameters
- str
Column
or column name A column of strings, each representing a UTF-8 byte sequence.
- str
- Returns
Column
the input string if it is a valid UTF-8 string, null otherwise.
See also
Examples
>>> import pyspark.sql.functions as sf >>> spark.range(1).select(sf.try_validate_utf8(sf.lit("SparkSQL"))).show() +---------------------------+ |try_validate_utf8(SparkSQL)| +---------------------------+ | SparkSQL| +---------------------------+