//提交代码包
// /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. 使用TVTK库创建一个矩形视图

    from tvtk.api import tvtk # s=tvtk.ConeSource(height=,radius=) # print(s.center) #创建一个长方体数据源,并同时设置长宽 ...

  2. jsp下载word

    <%@ page language="java" contentType="application/msword;charset=utf-8"%> ...

  3. Linux终端记录神器

    我们在调试程序的时候,免不了要去抓一些 log ,然后进行分析.如果 log 量不是很大的话,那很简单,只需简单的复制粘贴就好.但是如果做一些压力测试,产生大量 log ,而且系统内存又比较小(比如嵌 ...

  4. TerminateProcess的使用问题

    最好时外部进程来结束目标进程,类似于任务管理器的结束目标进程方式.如果是自身进程想结束自身,可能不同版本的windows行为不一致,有一些能自身强制退出,有一些强制退出不了. 本来MSDN上就说了这个 ...

  5. C# 使用NLog记录日志入门操作

    环境:win7 64位, VS2010 1.首先用VS2010创建命令行工程NLogDemo 2.在程序包管理器控制台中输入:Install-Package NLog -Version 4.4.12 ...

  6. JVM源码分析之Object.wait/notify实现(转载)

    最简单的东西,往往包含了最复杂的实现,因为需要为上层的存在提供一个稳定的基础,Object作为java中所有对象的基类,其存在的价值不言而喻,其中wait和notify方法的实现多线程协作提供了保证. ...

  7. windows环境telnet发送命令

    telnet *.*.*.* port ,然后crtl+]进入命令模式,使用send发送消息,如:send hello,murphy 常用命令: open : 使用 openhostname 可以建立 ...

  8. SNF快速开发平台--规则引擎介绍和使用文档

    设计目标: a) 规则引擎语法能够满足分单,计费,WMS策略的配置要求.语法是一致和统一的 b) 能够在不修改规则引擎模块的情况下,加入任意一个新的规则:实现上述需求之外的规则配置需求 c) 运算速度 ...

  9. 空间谱专题13:联合解算DOA(ML/AP)

    其中作者:桂. 时间:2017-10-16  07:51:40 链接:http://www.cnblogs.com/xingshansi/p/7675380.html 前言 主要记录二维测向中,分别利 ...

  10. Error loading page Domain: WebKitErrorDomain Error Code: 101

    使用 WebView 组件,loading的过程中出现这个错误. 解决方案: webVIew 里面加 renderError={ (e) => { if (e === 'WebKitErrorD ...