SparkSql读取HDFS文件写出到MySQL
用SparkSQL来处理存放在HDFS文件,操作起来优雅简洁,同时写出到数据库中,比SparkRDD操作跟简单,在此之前确保HDFS所在服务器的访问端口是否开通一般为9000端口,文章里是8020端口。文章中使用的数据为MongoDB的数据到HDFS上的,数据格式(BSON)和JSON是大同小异的。
数据格式
{
"oil":0,"simNo":"010000000002","carId":304648943587868672,"address":null,"satelliteNumber":0,"reportTime":1592443939000,"status":0,"terminalId":"3212025","longitude":119358299,"plateNo":"苏A00002","statusComments":"ACC开 定位 南纬 西经 停运状态 经纬度已经保密插件加密 车辆油路断开 车辆电路断开 车门加锁 前门开 中门开 后门开 驾驶席门开 使用GPS卫星进行定位 使用北斗卫星进行定位 ","timeIntervalStatus":null,"@version":"1","course":0,"alarmComments":null,"speed":800,"altitude":25,"latitude":32188034,"parkTime":0,"@timestamp":"2020-06-29T17:31:44.861Z","alarmFlag":0,"terminalDriver":null,"mileage":552954}
{
"oil":0,"simNo":"064606108552","carId":299525840931176448,"address":null,"satelliteNumber":0,"reportTime":1592443998000,"status":0,"terminalId":"2359641","longitude":119358135,"plateNo":"苏L75735","statusComments":"ACC开 定位 南纬 西经 停运状态 经纬度已经保密插件加密 车辆油路断开 车辆电路断开 车门加锁 前门开 中门开 后门开 驾驶席门开 使用GPS卫星进行定位 使用北斗卫星进行定位 ","timeIntervalStatus":null,"@version":"1","course":0,"alarmComments"