这是一个例子
我有一个数据框
+---+---------+----+------------+-----+
| 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 |
+---+---------+----+------------+-----+------+
我怎样才能做到,希望你的帮助,谢谢!
答案 0 :(得分:0)
让我们命名数据框A。
A.registerTempTable("tableA")
b = sqlContext.sql("select `id`,`name`,age,describle,value,length(`name`)+length(`describle`) as `length` from tableA")