//提交代码包
// /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. solr中的一些常见错误

    (1)Caused by: java.lang.ClassNotFoundException: Unable to load jdbcDataSource or org.apache.solr.han ...

  2. Docker machine(Docker 虚拟机)

    安装docker [root@lianxi ~]# yum -y install docker 启动docker [root@lianxi ~]# systemctl start docker 下载D ...

  3. U3D面试五

    U3D面试题 配置Unity3D调试环境 Visual Studio Tools for Unity 访问http://unityvs.com 安装对应的版本 使用方法(生成项目文件,如何调试) Ar ...

  4. Codeforces Round #532 (Div. 2)

    Codeforces Round #532 (Div. 2) A - Roman and Browser #include<bits/stdc++.h> #include<iostr ...

  5. ELASTIC API

    运维常用API. curl -XGET 'localhost:9200/_cat/indices?v&pretty' #查看索引 curl -XGET 'localhost:9200/_cat ...

  6. boost 1.67编译VS2017版本

    最近想系统学习并使用一下boost的asio异步网络库,所以需要编译boost库使用,下面简单介绍如何编译. 编译环境 boost1.67版本,windows 10,VS2017 下载boost 建议 ...

  7. spring cloud: 使用consul来替换eureka

    eureka官方已经正式宣布:自2.0起不再维护该项目,并在github 项目wiki上放出了一段吓唬人的话: 大意就是:从2.x起,官方不会继续开发了,如果需要使用2.x,风险自负.但其实我觉得问题 ...

  8. Revit API创建标注NewTag

    start ;             )                 {                     eId = item;                 }            ...

  9. ZwQuerySystemInformation枚举内核模块及简单应用

    简单说,即调用第11号功能,枚举一下内核中已加载的模块.部分代码如下://功能号为11,先获取所需的缓冲区大小ZwQuerySystemInformation(SystemModuleInformat ...

  10. 1.2 Stream API

    引例: List<String> strList = Arrays.asList("zhaojigang","nana","tianya& ...