//提交代码包
// /usr/local/spark/bin$ spark-submit --class "getkv" /data/chun/sparktes.jar import org.apache.spark.sql.{DataFrame, Row, SQLContext, SaveMode}
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.hive.HiveContext
object split {
def main(args:Array[String])
{ val cf = new SparkConf().setAppName("ass").setMaster("local")
val sc = new SparkContext(cf)
val sqlContext = new SQLContext(sc)
val hc = new HiveContext(sc)
val format=new java.text.SimpleDateFormat("yyyy-MM-dd")
val date=format.format(new java.util.Date().getTime-****) val lg= sc.textFile("hdfs://master:9000/data/"+date+"/*/*.gz") val filed1=lg.map(l=>(l.split("android_id\":\"").last.split("\"").head.toString,
l.split("anylst_ver\":").last.split(",").head.toString,
l.split("area\":\"").last.split("\"").head,
l.split("build_CPU_ABI\":\"").last.split("\"").head,
l.split("build_board\":\"").last.split("\"").head,
l.split("build_model\":\"").last.split("\"").head,
l.split("\"city\":\"").last.split("\"").head,
l.split("country\":\"").last.split("\"").head,
l.split("cpuCount\":").last.split(",").head,
l.split("cpuName\":\"").last.split("\"").head,
l.split("custom_uuid\":\"").last.split("\"").head,
l.split("cid\":\"").last.split("\"").head,
l.split("definition\":\"").last.split("\"").head,
l.split("firstTitle\":\"").last.split("\"").head,
l.split("modeType\":\"").last.split("\"").head,
l.split("pageName\":\"").last.split("\"").head,
l.split("playIndex\":\"").last.split("\"").head,
l.split("rectime\":").last.split(",").head,
l.split("time\":\"").last.split("\"").head))
//val F1=filed1.toDF("custom_uuid","region","screenHeight","screenWidth","serial_number","touchMode","umengChannel","vercode","vername","wlan0_mac","rectime","time")
val scoreDataFrame1 = hc.createDataFrame(filed1).toDF("android_id","anylst_ver","area","build_CPU_ABI","build_board","build_model","city","country","cpuCount","cpuName","custom_uuid","cid","definition","firstTitle","modeType","pageName","playIndex","rectime","time")
scoreDataFrame1.write.mode(SaveMode.Append).saveAsTable("test.f1") val filed2=lg.map(l=>(l.split("custom_uuid\":\"").last.split("\"").head,
l.split("playType\":\"").last.split("\"").head,
l.split("prevName\":\"").last.split("\"").head,
l.split("prevue\":").last.split(",").head,
l.split("siteName\":\"").last.split("\"").head,
l.split("title\":\"").last.split("\"").head,
l.split("uuid\":\"").last.split("\"").head,
l.split("vod_seek\":\"").last.split("\"").head,
l.split("device_id\":\"").last.split("\"").head,
l.split("device_name\":\"").last.split("\"").head,
l.split("dpi\":").last.split(",").head,
l.split("eth0_mac\":\"").last.split("\"").head,
l.split("ip\":\"").last.split("\"").head,
l.split("ipaddr\":\"").last.split("\"").head,
l.split("isp\":\"").last.split("\"").head,
l.split("largeMem\":").last.split(",").head,
l.split("limitMem\":").last.split(",").head,
l.split("packageName\":\"").last.split("\"").head,
l.split("rectime\":").last.split(",").head,
l.split("time\":\"").last.split("\"").head))
import sqlContext.implicits._
val scoreDataFrame2 = hc.createDataFrame(filed2).toDF("custom_uuid","playType","prevName","prevue","siteName","title","uuid","vod_seek","device_id","device_name","dpi","eth0_mac","ip","ipaddr","isp","largeMem","limitMem","packageName","rectime","time")
scoreDataFrame2.write.mode(SaveMode.Append).saveAsTable("test.f2")
// val filed3=lg.map(l=>(l.split("custom_uuid\":\"").last.split("\"").head,
l.split("region\":\"").last.split("\"").head,
l.split("screenHeight\":").last.split(",").head,
l.split("screenWidth\":").last.split(",").head,
l.split("serial_number\":\"").last.split("\"").head,
l.split("touchMode\":").last.split(",").head,
l.split("umengChannel\":\"").last.split("\"").head,
l.split("vercode\":").last.split(",").head,
l.split("vername\":\"").last.split("\"").head,
l.split("wlan0_mac\":\"").last.split("\"").head,
l.split("rectime\":").last.split(",").head,
l.split("time\":\"").last.split("\"").head
)) import sqlContext.implicits._
val scoreDataFrame3= hc.createDataFrame(filed3).toDF("custom_uuid","region","screenHeight","screenWidth","serial_number","touchMode","umengChannel","vercode","vername","wlan0_mac","rectime","time")
scoreDataFrame3.write.mode(SaveMode.Append).saveAsTable("test.f3") }
}

spark 解析非结构化数据存储至hive的scala代码的更多相关文章

  1. MySQL 5.7:非结构化数据存储的新选择

    本文转载自:http://www.innomysql.net/article/23959.html (只作转载, 不代表本站和博主同意文中观点或证实文中信息) 工作10余年,没有一个版本能像MySQL ...

  2. Spark如何与深度学习框架协作,处理非结构化数据

    随着大数据和AI业务的不断融合,大数据分析和处理过程中,通过深度学习技术对非结构化数据(如图片.音频.文本)进行大数据处理的业务场景越来越多.本文会介绍Spark如何与深度学习框架进行协同工作,在大数 ...

  3. Python爬虫(九)_非结构化数据与结构化数据

    爬虫的一个重要步骤就是页面解析与数据提取.更多内容请参考:Python学习指南 页面解析与数据提取 实际上爬虫一共就四个主要步骤: 定(要知道你准备在哪个范围或者网站去搜索) 爬(将所有的网站的内容全 ...

  4. 结构化数据(structured),半结构化数据(semi-structured),非结构化数据(unstructured)

    概念 结构化数据:即行数据,存储在数据库里,可以用二维表结构来逻辑表达实现的数据. 半结构化数据:介于完全结构化数据(如关系型数据库.面向对象数据库中的数据)和完全无结构的数据(如声音.图像文件等)之 ...

  5. 结构化数据、半结构化数据、非结构化数据——Hadoop处理非结构化数据

    刚开始接触Hadoop ,指南中说Hadoop处理非结构化数据,学习数据库的时候,老师总提结构化数据,就是一张二维表,那非结构化数据是什么呢?难道是文本那样的文件?经过上网搜索,感觉这个帖子不错 网址 ...

  6. Scrapy系列教程(2)------Item(结构化数据存储结构)

    Items 爬取的主要目标就是从非结构性的数据源提取结构性数据,比如网页. Scrapy提供 Item 类来满足这种需求. Item 对象是种简单的容器.保存了爬取到得数据. 其提供了 类似于词典(d ...

  7. hbase非结构化数据库与结构化数据库比较

    目的:了解hbase与支持海量数据查询的特性以及实现方式 传统关系型数据库特点及局限 传统数据库事务性特别强,要求数据完整性及安全性,造成系统可用性以及伸缩性大打折扣.对于高并发的访问量,数据库性能不 ...

  8. 利用Gson和SharePreference存储结构化数据

    问题的导入 Android互联网产品通常会有很多的结构化数据需要保存,比如对于登录这个流程,通常会保存诸如username.profile_pic.access_token等等之类的数据,这些数据可以 ...

  9. Spark读取结构化数据

    读取结构化数据 Spark可以从本地CSV,HDFS以及Hive读取结构化数据,直接解析为DataFrame,进行后续分析. 读取本地CSV 需要指定一些选项,比如留header,比如指定delimi ...

随机推荐

  1. BZOJ2264 : Free Goodies

    如果Jan先手,那么可以放入一个对Petra来说价值$inf$的物品,就变成了Petra先手. 对于Petra来说,拿物品的顺序是固定的,按这个顺序排序. 那么如果把Petra的选择看成$($,Jan ...

  2. android 6.0 动态权限

    Android 6.0 动态权限: 除了要在AndroidManifest.xml中申请外,还需使用时,请求用户允许授权. 以下是需要单独申请的权限,共分为9组,每组只要有一个权限申请成功了,就默认整 ...

  3. linux 启动 Oracle 实例

    启动数据库实例,分为两步:第一步,启动监听:第二步,启动数据库实例. 一.如何启动数据库实例 1.进入到sqlplus启动实例 --“切换到oracle用户” su - oracle --“打开监听” ...

  4. caffe实际运行中遇到的问题

    https://blog.csdn.net/u010417185/article/details/52649178 1.均值计算是否需要统一图像的尺寸? 在图像计算均值时,应该先统一图像的尺寸,否则会 ...

  5. Linux 中C/C++ search path(头文件搜索路径)

    https://blog.csdn.net/BjarneCpp/article/details/76135980 起因 我拿到了一套Linux下的C++代码,代码中有这个头文件#include < ...

  6. [Docker] Benefits of Multi-stage Builds

    The benfits of multi-stage builds: Avoid manual creation of intermediate images Reduce complexity Se ...

  7. 最新版本Zabbix3.4+Grafana5 整合部署

    一.Grafana简介 Grafana是一个可视化面板(Dashboard),有着非常漂亮的图表和布局展示,功能齐全的度量仪表盘和图形编辑器,支持Graphite.elasticsearch.zabb ...

  8. MSSQL存储过程

    存储过程的种类:       1.系统存储过程.        以sp_开头      2.扩展存储过程.        以xp_开头      3.用户定义存储过程. --重新编译存储过程 exec ...

  9. ionic 001

    安装和穿件app npm install -g cordova ionic 使用模板创建app ionic start myApp blank ionic start myApp tabs ionic ...

  10. MySql之触发器的使用

    一:触发器的使用场景 当数据库的记录发生变化时,自动触发某些操作. MySQL的触发器响应三种操作,六种场合: 三种操作:DELETE.INSERT.UPDATE. 六种场合:三种操作的BEFORE. ...