middle
/**
* Created by lkl on 2017/7/31.
*/
/**
* Created by lkl on 2017/6/26.
*///spark-shell --driver-class-path /home/hadoop/test/mysqljdbc.jar
import java.math.BigDecimal
import java.sql.{DriverManager, ResultSet}
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
import java.text.SimpleDateFormat
import java.util.Date
object middle {
val rl= "jdbc:mysql://10.19.65.17:54321/emotion?user=emotion&password=qingxu&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false"
classOf[com.mysql.jdbc.Driver]
val conn = DriverManager.getConnection(rl)
def main(args: Array[String]) {
val conf = new SparkConf()
val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val titlesplit1 = sqlContext.jdbc("jdbc:mysql://10.19.65.17:54321/emotion?user=emotion&password=qingxu", "titlesplit")
val titlesplit = titlesplit1.toDF().registerTempTable("titlesplit")
val category1 = sqlContext.jdbc("jdbc:mysql://10.19.65.17:54321/emotion?user=emotion&password=qingxu", "category")
val category = category1.toDF().registerTempTable("category")
val categorys=sqlContext.sql("select category.`id`,category.`number`,category.`category`,category.`words` from category").toDF("id","number","category","words").registerTempTable("categorys")
val layer1 = sqlContext.jdbc("jdbc:mysql://10.19.65.17:54321/emotion?user=emotion&password=qingxu", "layer")
val layer = layer1.toDF().registerTempTable("layer")
val format = new java.text.SimpleDateFormat("yyyyMMdd")
val date = format.format(new java.util.Date().getTime())
import sqlContext.implicits._
val value = sqlContext.sql("SELECT titlesplit.`innserSessionid`," +
"titlesplit.`times`,categorys.`number`," +
"categorys.`category`," +
"SUM(layer.`VALUE`) svalue," +
"COUNT(DISTINCT titlesplit.`id`) AS wordscount," +
"COUNT(DISTINCT categorys.`id`) AS categoryscount," +
"COUNT(DISTINCT categorys.`id`)/COUNT(DISTINCT titlesplit.`id`) AS rank" +
" FROM titlesplit " +
" LEFT JOIN `layer` " +
"ON titlesplit.`words`=layer.`words` " +
" LEFT JOIN categorys " +
" ON titlesplit.`words`=categorys.`words`" +
"GROUP BY titlesplit.`innserSessionid`,titlesplit.`times`," +
"categorys.`number`,categorys.`category`").toDF("innserSessionid", "times", "number","category", "svalue", "wordscount", "categoryscount", "rank")
// value.insertIntoJDBC(rl,"middles",false)
//val jo = value.toDF("innserSessionid", "times", "category", "svalue", "wordscount", "categoryscount", "rank")
val p1 = value.map(p => {
val v0 = p.getString(0)
val v1 = p.getString(1)
val v2 = p.getString(2)
val v3 = p.getString(3)
val v4 = p.getDecimal(4)
var v5 = p.getLong(5)
val v6 = p.getLong(6)
val v7 = p.getDouble(7)
(v0,v1,v2,v3,v4,v5,v6,v7)
})
p1.foreach(p => {
val v1=p._1
val v2=p._2
val v3=p._3
val v4=p._4
val v5=p._5
val v6=p._6
val v7=p._7
val v8=p._8
val format2 = new java.text.SimpleDateFormat("yyyy-MM-dd")
val dat = format2.format(new java.util.Date().getTime() - 1 * 24 * 60 * 60 * 1000).toString
if(v2==dat)
{
insert(v1,v2,v3,v4,v5,v6,v7,v8)
}
})
conn.close()
}
def insert (value0:String,value1:String,value2:String,value3:String,value4:BigDecimal,value5:Long,value6:Long,value7:Double): Unit ={
val statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)
// CREATE TABLE words2(innersessionId VARCHAR(100),words VARCHAR(100), VARCHAR(100),posit VARCHAR(100),va VARCHAR(100))
try {
val prep = conn.prepareStatement("INSERT INTO middle(innserSessionid,times,number,category,svalue,wordscount,categoryscount,rank) VALUES (?,?,?,?,?,?,?,?) ")
prep.setString(1,value0)
prep.setString(2,value1)
prep.setString(3,value2)
prep.setString(4,value3)
prep.setBigDecimal(5,value4)
prep.setLong(6,value5)
prep.setLong(7,value6)
prep.setDouble(8,value7)
prep.executeUpdate
} catch{
case e:Exception =>e.printStackTrace
}
finally {
}
}
}
middle的更多相关文章
- 代码的坏味道(21)——中间人(Middle Man)
坏味道--中间人(Middle Man) 特征 如果一个类的作用仅仅是指向另一个类的委托,为什么要存在呢? 问题原因 对象的基本特征之一就是封装:对外部世界隐藏其内部细节.封装往往伴随委托.但是人们可 ...
- 【BZOJ-2653】middle 可持久化线段树 + 二分
2653: middle Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1298 Solved: 734[Submit][Status][Discu ...
- Who's in the Middle[HDU1157]
Who's in the Middle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...
- vertical-align:middle
img style="vertical-align:middle;" src="<%=basePath%>/images/ckpy.png" > ...
- 【leetcode】Sort List (middle)
Sort a linked list in O(n log n) time using constant space complexity. 思路: 用归并排序.设输入链表为S,则先将其拆分为前半部分 ...
- 【leetcode】Reorder List (middle)
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...
- 【leetcode】Number of Islands(middle)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- 运用vertical:middle 使得元素垂直居中
我要垂直居中我要垂直居中我要垂直居中我要垂直居中我要垂直居中垂直居中垂直居中垂直居中中垂直居中垂直居中 <!-- 第一步:主题元素display:inline-block;第二步:插入辅助元 ...
- Who's in the Middle 分类: POJ 2015-06-12 19:45 11人阅读 评论(0) 收藏
Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34155 Accepted: 1 ...
随机推荐
- iOS录制视频
随着每一代 iPhone 处理能力和相机硬件配置的提高,使用它来捕获视频也变得更加有意思.它们小巧,轻便,低调,而且与专业摄像机之间的差距已经变得非常小,小到在某些情况下,iPhone 可以真正替代它 ...
- 基于jQuery仿去哪儿城市选择代码
基于jQuery仿去哪儿城市选择代码.这是一款使用的jQuery城市选择特效代码下载.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class="lin ...
- 解密SVM系列(二):SVM的理论基础
上节我们探讨了关于拉格朗日乘子和KKT条件.这为后面SVM求解奠定基础,本节希望通俗的细说一下原理部分. 一个简单的二分类问题例如以下图: 我们希望找到一个决策面使得两类分开.这个决策面一般表示就是W ...
- 最美应用API接口分析
最美应用API接口分析html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .CodeMirror-scr ...
- CSS一个元素同时使用多个类选择器(class selector)
CSS类选择器参考手册 一个元素同时使用多个类选择器 CSS中类选择器用点号表示.实际项目中一个div元素为了能被多个样式表匹配到(样式复用),通常div的class中由好几段组成,如<div ...
- C++实现的服务不可用发送报警邮件
正在看C++,我主业是Java开发,但是最近服务不太稳定,自己用C++造了个小轮子. 配置好要监控的访问路径,IP.端口号和路径.涉及到的知识点有以下几个部分: 构造函数与析构函数 内存的分配与释放( ...
- 利用jQuery中live为动态生成Dom添加datepicker效果
利用Live属性,focus时重新绑定控件 $(".datepickerDom").live("focus", function () { $(this).da ...
- Java log4j slf4j 日志配置笔记
http://www.cnblogs.com/Scott007/p/3269018.html 日志的打印,在程序中是必不可少的,如果需要将不同的日志打印到不同的地方,则需要定义不同的Appender, ...
- MSXML4 SP2 sp3安装时出错
没有启动Windows Module Installer 服务或者windows installer服务,重启试试 Windows Installer Cleanup Tool清理早期的在选项框中找到 ...
- 淘宝开放平台获取沙箱token
沙箱环境的文档都是错的,直接使用以下地址: 输入淘宝测试账号: sandbox_c_1 密码: taobao1234 https://login.tbsandbox.com/member/log ...