Commit e703ed26 authored by 高雅喆's avatar 高雅喆

add GetDevicePortrait

parent d905ce69
......@@ -543,6 +543,7 @@ object GetDevicePortrait {
val ti = new TiContext(sc)
ti.tidbMapTable(dbName = "jerry_prod",tableName = "data_feed_click")
ti.tidbMapTable(dbName = "jerry_prod",tableName = "diary_feat")
import sc.implicits._
val stat_date = param.date.replace("-","")
......@@ -570,19 +571,17 @@ object GetDevicePortrait {
val max_count_tag = sc.sql(
s"""
|select a.device_id,a.stat_date,a.level1_id,a.level1_count
|select a.device_id,a.stat_date,a.level1_id as max_level1_id,a.level1_count as max_level1_count
|from tag_count a
|inner join
|(select device_id,max(level1_count) as max_count from tag_count group by device_id) b
|on a.level1_count = b.max_count and a.device_id = b.device_id
""".stripMargin
)
max_count_tag.show()
println(max_count_tag.count())
// GmeiConfig.writeToJDBCTable(diary_tag,"diary_feat",SaveMode.Overwrite)
).rdd.map(x => (x(0).toString,x(1).toString,x(2).toString,x(3).toString))
max_count_tag.foreachPartition(GmeiConfig.updateDeviceFeat)
max_count_tag.take(10).foreach(println)
println(max_count_tag.count())
sc.stop()
......
......@@ -82,7 +82,7 @@ object GmeiConfig extends Serializable {
def updateDeviceFeat(iterator: Iterator[(String,String,String,String)]): Unit ={
var conn: Connection= null
var ps:java.sql.PreparedStatement=null
val sql=s"replace into device_feat(device_id,stat_date,level1_id,level1_count) values(?,?,?,?)"
val sql=s"replace into device_feat(device_id,stat_date,max_level1_id,max_level1_count) values(?,?,?,?)"
conn=DriverManager.getConnection("jdbc:mysql://10.66.157.22:4000/jerry_prod","root","3SYz54LS9#^9sBvC")
ps = conn.prepareStatement(sql)
try{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment