mport org.apache.spark.sql.types.{StructType,StructField,StringType, IntegerType, LongType}
import java.util.ArrayList
import org.apache.spark.sql._

val dataList = new util.ArrayList[Row]()
dataList.add(Row("ming",20,15552211521L))
dataList.add(Row("hong",19,13287994007L))
dataList.add(Row("zhi",21,15552211523L))

val df = sqlContext.createDataFrame(dataList,schema)

scala> df.printSchema
root
 |-- name: string (nullable = true)
 |-- age: integer (nullable = true)
 |-- phone: long (nullable = true)

// 修改数据类型
scala> val df1 = df.withColumn("age",col("age").cast(StringType))
df1: org.apache.spark.sql.DataFrame = [name: string, age: string, phone: bigint]

scala> df1.printSchema
root
 |-- name: string (nullable = true)
 |-- age: string (nullable = true)
 |-- phone: long (nullable = true)

 

相关文章:

  • 2022-01-05
  • 2021-07-06
  • 2022-12-23
  • 2021-08-27
  • 2021-06-07
  • 2021-06-09
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2021-12-05
  • 2021-05-26
相关资源
相似解决方案