Commit 404ad9fa authored by Pengfei Xue's avatar Pengfei Xue

add chain rate

parent 31f13811
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8.0_212" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -30,7 +30,8 @@ object Main {
}
// check pv
pvReferCheker.check(spark, partition_date)
// pvReferCheker.check(spark, partition_date)
actionCheck.check(spark, partition_date)
spark.stop()
}
......
package com.gmei.data.dq
import java.text.SimpleDateFormat
import java.util.Date
import org.apache.spark.sql.SparkSession
object actionCheck {
import java.util.Calendar
private def getYesterday(date: Date) = {
val cal = Calendar.getInstance
cal.setTime(date)
cal.add(Calendar.DATE, -1)
cal.getTime
}
def check(sc: SparkSession, partition_date: String) = {
import sc.implicits._
val dateFormat = new SimpleDateFormat("yyyyMMdd")
val time_date = dateFormat.parse(partition_date)
val yesterday = getYesterday(time_date)
val df = sc.sql(
s"""
|select
| a.partition_date as today,
| b.partition_date as yesterday,
| a.cl_type,
| a.app_version,
| a.c as todayCount,
| b.c as yesterdayCount,
| case when b.c = 0 then 1.0 else (a.c - b.c) * 1.0 / b.c end as chainRate
|(
| select partition_date, cl_type, app_version, count(1) as c
| from online.bl_hdfs_maidian_updates
| where partition_date = '${partition_date}'
| group by partition_date, cl_type, app_version
|) a left join (
| select
| select partition_date, cl_type, app_version, count(1) as c
| from online.bl_hdfs_maidian_updates
| where partition_date = '${yesterday}'
| group by partition_date, cl_type, app_version
|) b on a.cl_type = b.cl_type and a.app_version = b.app_version
""".stripMargin)
df.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