pyspark.sql.functions.length

pyspark.sql.functions.length(col: ColumnOrName) → pyspark.sql.column.Column

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.

Examples

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