pyspark.sql.functions.length

pyspark.sql.functions.length(col)[source]

Computes the character length of string data or number of bytes of binary data. The length of character data includes the trailing spaces. The length of binary data includes binary zeros.

New in version 1.5.0.

Examples

>>> spark.createDataFrame([('ABC ',)], ['a']).select(length('a').alias('length')).collect()
[Row(length=4)]