pyspark.sql.functions.validate_utf8#

pyspark.sql.functions.validate_utf8(str)[source]#

Returns the input value if it corresponds to a valid UTF-8 string, or emits an error otherwise.

Added in version 4.0.0.

Parameters:
strColumn or column name

A column of strings, each representing a UTF-8 byte sequence. A column that evaluates to a string.

Returns:
Column

the input string if it is a valid UTF-8 string, error otherwise. Returns a column that evaluates to a string.

Examples

>>> import pyspark.sql.functions as sf
>>> spark.range(1).select(sf.validate_utf8(sf.lit("SparkSQL"))).show()
+-----------------------+
|validate_utf8(SparkSQL)|
+-----------------------+
|               SparkSQL|
+-----------------------+