这是一个示例
我有一个数据帧
+---+---------+----+------------+-----+
| id| name| age| describle|value|
+---+---------+----+------------+-----+
| 0|hansongbo|null| he is great| 11|
| 1| marong| 23| null| null|
| 2|hansongbo| 34| null| null|
| 3| marong| 34|she love han| 12|
+---+---------+----+------------+-----+
现在我要计算所有字符串列的长度,结果是
+---+---------+----+------------+-----+------+
| id| name| age| describle|value|length|
+---+---------+----+------------+-----+------+
| 0|hansongbo|null| he is great| 11| 20 |
| 1| marong| 23| null| null| 6 |
| 2|hansongbo| 34| null| null| 9 |
| 3| marong| 34|she love han| 12| 18 |
+---+---------+----+------------+-----+------+
我怎么能做到,希望你的帮助,谢谢!
让我们将数据帧命名为 A。
A.registerTempTable("tableA")
b = sqlContext.sql("select `id`,`name`,age,describle,value,length(`name`)+length(`describle`) as `length` from tableA")