Commit 23858c1c authored by 王志伟's avatar 王志伟

new file

parent 930f74e8
package com.gmei
import java.io.Serializable
import com.gmei.WeafareStat.{defaultParams, parser}
import org.apache.spark.sql.{SaveMode, TiContext}
import org.apache.log4j.{Level, Logger}
import scopt.OptionParser
import com.gmei.lib.AbstractParams
object strategy_clk_imp_oldUser {
Logger.getLogger("org.apache.spark").setLevel(Level.WARN)
Logger.getLogger("org.apache.eclipse.jetty.server").setLevel(Level.OFF)
case class Params(env: String = "dev"
) extends AbstractParams[Params] with Serializable
val defaultParams = Params()
val parser = new OptionParser[Params]("Feed_EDA") {
head("WeafareStat")
opt[String]("env")
.text(s"the databases environment you used")
.action((x, c) => c.copy(env = x))
note(
"""
|For example, the following command runs this app on a tidb dataset:
|
| spark-submit --class com.gmei.WeafareStat ./target/scala-2.11/feededa-assembly-0.1.jar \
""".stripMargin +
s"| --env ${defaultParams.env}"
)
}
def main(args: Array[String]): Unit = {
parser.parse(args, defaultParams).map { param =>
GmeiConfig.setup(param.env)
val spark_env = GmeiConfig.getSparkSession()
val sc = spark_env._2
val ti = new TiContext(sc)
ti.tidbMapTable(dbName = "jerry_prod", tableName = "diary_video")
ti.tidbMapTable(dbName = "jerry_prod", tableName = "data_feed_click")
ti.tidbMapTable(dbName = "jerry_prod", tableName = "blacklist")
ti.tidbMapTable(dbName = "jerry_test", tableName = "bl_device_list")
import sc.implicits._
val stat_date = GmeiConfig.getMinusNDate(1)
println(stat_date)
val partition_date = stat_date.replace("-","")
val decive_id_oldUser = sc.sql(
s"""
|select distinct(device_id) as decive_id_oldUser
|from online.ml_device_day_active_status
|where active_type = '4'
|and partition_date ='${partition_date}'
""".stripMargin
)
decive_id_oldUser.show()
decive_id_oldUser.createOrReplaceTempView("device_id_tmp1")
val strategies = Seq("[1|2]$","[3|4]$","[5|6]$","[7|8]$")
for (strategy <- strategies){
val clk_count = sc.sql(
s"""
|select '${stat_date}' as stat_date, count(cid_id) as get_clk_count
|from jerry_prod.data_feed_click jd inner join device_id_tmp1
|on jd.device_id = device_id_tmp1.decive_id_oldUser
|where (jd.cid_type = 'diary' or jd.cid_type = 'diary_video')
|and jd.device_id regexp'${strategy}'
|and jd.device_id not in (select device_id from jerry_test.bl_device_list)
|and jd.device_id not in (select device_id from jerry_prod.blacklist)
|and jd.stat_date ='${stat_date}'
""".stripMargin
)
val imp_count = sc.sql(
s"""
|select '${stat_date}' as stat_date, count(cid_id) as get_imp_count
|from jerry_prod.data_feed_exposure je inner join device_id_tmp1
|on je.device_id = device_id_tmp1.decive_id_oldUser
|where je.cid_type = 'diary'
|and je.device_id regexp'${strategy}'
|and je.device_id not in (select device_id from jerry_test.bl_device_list)
|and je.device_id not in (select device_id from jerry_prod.blacklist)
|and je.stat_date ='${stat_date}'
""".stripMargin
)
val result = clk_count.join(imp_count,stat_date)
result.show()
}
}
}
}
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