아래 샘플 코드를 제공함.

 

val df = Seq(
(1, "abc"),
(2, "def"),
(3, "ghi")
).toDF("num","str")

 

scala> df.show

+---+---+
|num|str|
+---+---+
| 1|abc|
| 2|def|
| 3|ghi|
+---+---+

 

val toSize = udf((payload:String) => payload.size)

 

scala> df.withColumn("ns", toSize(col("str"))).show
+---+---+---+
|num|str| ns|
+---+---+---+
| 1|abc| 3|
| 2|def| 3|
| 3|ghi| 3|
+---+---+---+

 

 

 

+ Recent posts