Commit 7dc050e7 authored by 张彦钊's avatar 张彦钊

Merge branch 'master' of git.wanmeizhensuo.com:ML/ffm-baseline

修改训练集sql
parents 14618373 071d018b
...@@ -51,8 +51,8 @@ object data_feed_exposure_precise { ...@@ -51,8 +51,8 @@ object data_feed_exposure_precise {
ti.tidbMapTable(dbName = "jerry_prod", tableName = "merge_queue_table") ti.tidbMapTable(dbName = "jerry_prod", tableName = "merge_queue_table")
// val stat_date = GmeiConfig.getMinusNDate(1) val stat_date = GmeiConfig.getMinusNDate(1)
val stat_date = param.date // val stat_date = param.date
//println(param.date) //println(param.date)
val partition_date = stat_date.replace("-","") val partition_date = stat_date.replace("-","")
......
...@@ -559,7 +559,7 @@ object alpha_ctr { ...@@ -559,7 +559,7 @@ object alpha_ctr {
val click_count_recommend = sc.sql( val click_count_recommend = sc.sql(
s""" s"""
|select '${stat_date}' as stat_date,count(*) as count_recommend |select '${stat_date}' as stat_date,count(*) as click_count_recommend
|from bl.bl_alpha_et_mg_maidianlog_inc_d |from bl.bl_alpha_et_mg_maidianlog_inc_d
|where params['tab_name']='recommend' |where params['tab_name']='recommend'
|and params['page_name']='home' |and params['page_name']='home'
...@@ -571,7 +571,7 @@ object alpha_ctr { ...@@ -571,7 +571,7 @@ object alpha_ctr {
val click_count_focus = sc.sql( val click_count_focus = sc.sql(
s""" s"""
|select '${stat_date}' as stat_date,count(*) as count_focus |select '${stat_date}' as stat_date,count(*) as click_count_focus
|from bl.bl_alpha_et_mg_maidianlog_inc_d |from bl.bl_alpha_et_mg_maidianlog_inc_d
|where params['tab_name']='focus' |where params['tab_name']='focus'
|and params['page_name']='home' |and params['page_name']='home'
...@@ -581,7 +581,20 @@ object alpha_ctr { ...@@ -581,7 +581,20 @@ object alpha_ctr {
) )
click_count_focus.show() click_count_focus.show()
sc.sql(
def parse_json(str:String): Int ={
var t = List[Map[String, Any]]()
val result = JSON.parseFull(str)
result match {
case Some(b: List[Map[String, Any]]) => t = t ++ b
case None => println("Parsing failed")
case other => println("Unknown data structure: " + other)
}
t.size
}
val expoure_cards=sc.sql(
s""" s"""
|select params['exposure_cards'] as exposure_cards |select params['exposure_cards'] as exposure_cards
|from bl.bl_alpha_et_mg_maidianlog_inc_d |from bl.bl_alpha_et_mg_maidianlog_inc_d
...@@ -590,25 +603,34 @@ object alpha_ctr { ...@@ -590,25 +603,34 @@ object alpha_ctr {
|and type = 'page_precise_exposure' |and type = 'page_precise_exposure'
|and partition_day='${partition_date}' |and partition_day='${partition_date}'
""".stripMargin """.stripMargin
).rdd.map(row => { )
val lenth=row.toSeq.length val a =expoure_cards.rdd.map(row => row(0).toString).map(row=>parse_json(row)).collect().sum
(stat_date,lenth) val result1=List((stat_date,a))
}).toDF("stat_date","count").show() val df1 = sc.createDataFrame(result1).toDF("stat_date","expoure_count_recommend")
/*.rdd
.map(row =>{ val expoure_cards2=sc.sql(
val s = row.getAs[List[String]]("exposure_cards") s"""
(stat_date,s) |select params['exposure_cards'] as exposure_cards
}) |from bl.bl_alpha_et_mg_maidianlog_inc_d
//.reduceByKey((x,y) => x + y) |where params['tab_name'] = 'focus'
.toDF("stat_date","count").show() |and params['page_name'] = 'home'
*/ |and type = 'page_precise_exposure'
|and partition_day='${partition_date}'
""".stripMargin
)
val b =expoure_cards2.rdd.map(row => row(0).toString).map(row=>parse_json(row)).collect().sum
val result2=List((stat_date,b))
val df2 = sc.createDataFrame(result2).toDF("stat_date","expoure_count_focus")
val result=click_count_recommend.join(click_count_focus,"stat_date")
.join(df1,"stat_date")
.join(df2,"stat_date")
// GmeiConfig.writeToJDBCTable(click_count_recommend, "smart_rank_count", SaveMode.Append) GmeiConfig.writeToJDBCTable(result, "alpha_ctr", SaveMode.Append)
} }
......
...@@ -512,6 +512,7 @@ object diary_clk_card { ...@@ -512,6 +512,7 @@ object diary_clk_card {
""".stripMargin """.stripMargin
) )
device_id_oldUser.createOrReplaceTempView("device_id_old") device_id_oldUser.createOrReplaceTempView("device_id_old")
device_id_oldUser.show()
val clk_count_oldUser_Contrast_a = sc.sql( val clk_count_oldUser_Contrast_a = sc.sql(
...@@ -526,6 +527,7 @@ object diary_clk_card { ...@@ -526,6 +527,7 @@ object diary_clk_card {
|and ot.partition_date ='${partition_date}' |and ot.partition_date ='${partition_date}'
""".stripMargin """.stripMargin
) )
clk_count_oldUser_Contrast_a.show()
val clk_count_oldUser_Contrast_b = sc.sql( val clk_count_oldUser_Contrast_b = sc.sql(
s""" s"""
......
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