Commit 1799f3a4 authored by Pengfei Xue's avatar Pengfei Xue

dont group by app version

parent 4e10f4e5
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
run.sh run.sh
*.log *.log
target/ target/
.idea/
...@@ -27,33 +27,35 @@ object actionCheck { ...@@ -27,33 +27,35 @@ object actionCheck {
val df = sc.sql( val df = sc.sql(
s""" s"""
|select |select
| a.partition_date as today, | a.partition_date as date,
| b.partition_date as yesterday, | b.partition_date as yesterday,
| a.cl_type, | a.cl_type,
| a.app_version,
| a.action, | a.action,
| a.c as todayCount, | a.c as todayCount,
| b.c as yesterdayCount, | b.c as yesterdayCount,
| case when b.c = 0 then 1.0 else (a.c - b.c) * 1.0 / b.c end as chainRate | case when b.c = 0 then 1.0 else (a.c - b.c) * 1.0 / b.c end as chainRate
|from |from
|( |(
| select partition_date, cl_type, app_version, action, count(1) as c | select partition_date, cl_type, action, count(1) as c
| from online.bl_hdfs_maidian_updates | from online.bl_hdfs_maidian_updates
| where partition_date = '${partition_date}' | where partition_date = '${partition_date}'
| group by partition_date, cl_type, app_version, action | group by partition_date, cl_type, action
|) a left join ( |) a left join (
| select partition_date, cl_type, app_version, action, count(1) as c | select partition_date, cl_type, action, count(1) as c
| from online.bl_hdfs_maidian_updates | from online.bl_hdfs_maidian_updates
| where partition_date = '${yesterday}' | where partition_date = '${yesterday}'
| group by partition_date, cl_type, app_version, action | group by partition_date, cl_type, action
|) b on a.cl_type = b.cl_type and a.app_version = b.app_version and a.action = b.action |) b on a.cl_type = b.cl_type and a.action = b.action
""".stripMargin) """.stripMargin)
// write out to tidb // write out to tidb
Class.forName("com.mysql.jdbc.Driver")
val prop= new java.util.Properties() val prop= new java.util.Properties()
prop.put("user", "root") prop.put("user", "root")
prop.put("password", "3SYz54LS9#^9sBvC") prop.put("password", "3SYz54LS9#^9sBvC")
val url="jdbc:mysql://172.16.40.172:4000/jerry_test" prop.put("driver", "com.mysql.jdbc.Driver")
val url="jdbc:mysql://172.16.40.172:4000/jerry_test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true"
//df is a dataframe contains the data which you want to write. //df is a dataframe contains the data which you want to write.
df.write.mode(SaveMode.Append).jdbc(url,"maidian_action_check", prop) df.write.mode(SaveMode.Append).jdbc(url,"maidian_action_check", prop)
} }
......
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