我正在尝试在子字符串函数中使用长度函数DataFrame
但它给出了错误
val substrDF = testDF.withColumn("newcol", substring($"col", 1, length($"col")-1))
下面是错误
error: type mismatch;
found : org.apache.spark.sql.Column
required: Int
我用的是2.1。
可以使用函数“expr”:
val data = List("first", "second", "third")
val df = sparkContext.parallelize(data).toDF("value")
val result = df.withColumn("cutted", expr("substring(value, 1, length(value)-1)"))
result.show(false)
output:
+------+------+
|value |cutted|
+------+------+
|first |firs |
|second|secon |
|third |thir |
+------+------+
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)