利用spark读取csv文件乱码问题

ShadowXCX 2017-10-12 04:56:12
先上scala代码
val conf = new SparkConf().setAppName("Test1").setMaster("local")
val sparkContext = new SparkContext(conf)
val context = new SQLContext(sparkContext)
val fieldSchema = StructType(Array(
StructField("area", StringType, true),
StructField("province", StringType, true),
StructField("type", StringType, true),
StructField("name", StringType, true),
StructField("year", StringType, true),
StructField("quarter", StringType, true),
StructField("big", StringType, true),
StructField("pname", StringType, true),
StructField("price", DoubleType, true)
))

val taxiDF = context.read.format("com.databricks.spark.csv")
.option("header", "false")
.schema(fieldSchema)
.load("f:/data/aa.csv")


taxiDF.registerTempTable("t_test")

val area = context.sql("select * from t_test")

area.show()

sparkContext.stop()



结果为


按照系统提示邀请了一些人 麻烦了
...全文
1884 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
LinkSe7en 2017-10-15
  • 打赏
  • 举报
回复
编码问题吧?确认下csv文件是不是utf-8编码的

3,423

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧