目前,Spark 2.4.3 读取 text(文本文件)的时候,只支持 UTF-8 编码,如果是其他编码(例如 GBK),返回的 DataFrame 会出现乱码。
import org.apache.spark.sql.functions.{col, decode}
spark.read.format("text").load(filePath).select(decode(col("value"), encoding).as("value"))
目前,Spark 2.4.3 读取 text(文本文件)的时候,只支持 UTF-8 编码,如果是其他编码(例如 GBK),返回的 DataFrame 会出现乱码。
import org.apache.spark.sql.functions.{col, decode}
spark.read.format("text").load(filePath).select(decode(col("value"), encoding).as("value"))