//提交代码包
// /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. cocosCreator 新版本的动作函数API的应用

    利用触摸位置判断,点击的是屏幕的左侧还是右侧,控制主角左右移动: 见代码: InputControl:function () { var self=this; //cc.systemEvent sel ...

  2. Oracle中使用透明网关链接到Sqlserver(转)

    测试环境介绍 1.ORACLEServer   Database version:10.2.0 IP:192.168.1.5 ORACLE_HOME:D:\oracle\product\10.2.0\ ...

  3. 将控件画成圆角的效果(Delphi)

    最近在做一个Delphi的项目,常常要设计软件的界面,需要将控件画成圆角矩形.在Delphi中将控件画成圆角效果,可使用CreateRoundRectRgn函数.在此写了一个通用的函数,只要在用到改变 ...

  4. 后端把Long类型的数据传给前端,前端可能会出现精度丢失的情况,以及解决方案

    后端把Long类型的数据传给前端,前端可能会出现精度丢失的情况.例如:201511200001725439这样一个Long类型的整数,传给前端后会变成201511200001725440. 解决方法: ...

  5. windows server 2008 R2安装图片浏览器/照片查看器方法

    有用户的电脑安装了windows server 2008 R2,浏览大量图片时很不方便,因为系统中没有照片查看器或图片浏览器.其实,win2008 R2是有照片查看器的,只是默认情况下没有开启.参考以 ...

  6. iOS开发-UIView扩展CGRect

    关于UIView的位置都会遇到,一般需要改变UIView的位置,需要先获取原有的frame位置,然后在frame上面修改,有的时候如果只是改变了一下垂直方向的位置,宽度和高度的一种,这种写法很麻烦.下 ...

  7. 基于CentOS 搭建 FTP 文件服务

    系统要求: CentOS 7.2 64 位操作系统 一. 安装 VSFTPD (vsftpd 是在 Linux 上被广泛使用的 FTP 服务器,根据其[官网介绍][https://security.a ...

  8. 腾讯QQ会员中心g_tk32算法【C#版】

    最近用C#写qq活动辅助类程序,碰到了会员签到的gtk算法不一样,后来网上找了看,发现有php版的(https://www.oschina.net/code/snippet_1378052_48831 ...

  9. Golang——垃圾回收GC(2)

    1 垃圾回收中的重要概念 1.1 定义 In computer science, garbage collection (GC) is a form of automatic memory manag ...

  10. IT? 挨踢

    中国的IT,是最憋屈的IT. 他们掌握着正常人看不懂的英文+字母+标点符号组成的各类代码语言 他们像作者一样从无到有,从空白的白纸上敲出上千上万条华丽的计算机语言 但是他们承受着正常人的鄙视: 我的需 ...