Spark: Convert column of string to an array

前端 未结 3 1312
南笙
南笙 2020-12-24 04:46

How to convert a column that has been read as a string into a column of arrays? i.e. convert from below schema

scala> test.printSchema
root
 |-- a: long (         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 04:57

    In python (pyspark) it would be:

    from pyspark.sql.types import *
    from pyspark.sql.functions import col, split
    test = test.withColumn(
            "b",
            split(col("b"), ",\s*").cast("array").alias("ev")
     )
    

提交回复
热议问题