【发布时间】:2021-05-24 05:02:14
【问题描述】:
在 Spark 3.0.1、Scala 2.12 中,我得到了以下结果:
import spark.implicits._
import org.apache.spark.sql.functions._
Seq(("1987.01.01"))
.toDF("Input")
.select(
col("Input"),
to_date(col("Input"), "yyyy.M.d").as("format"),
length(col("Input")),
substring(col("Input"),1, length(col("Input")).cast("int")+0 )
).show()
command-1067744798817014:7: error: type mismatch;
found : org.apache.spark.sql.Column
required: Int
substring(col("Input"),1, length(col("Input")).cast("int")+0 )
^
所以我猜我有错误的“长度”函数,通过隐式导入或其他方式?
这行得通
Seq(("1987.01.01"))
.toDF("Input")
.select(
col("Input"),
to_date(col("Input"), "yyyy.M.d").as("format"),
length(col("Input"))
).show()
+----------+----------+-------------+
| Input| format|length(Input)|
+----------+----------+-------------+
|1987.01.01|1987-01-01| 10|
+----------+----------+-------------+
【问题讨论】:
标签: apache-spark apache-spark-sql