|
@@ -0,0 +1,107 @@
|
|
|
+package com.winhc.bigdata.spark.jobs
|
|
|
+
|
|
|
+import com.winhc.bigdata.spark.udf.CompanyMapping
|
|
|
+import com.winhc.bigdata.spark.utils.{BaseUtil, LoggingUtils, SparkUtils}
|
|
|
+import org.apache.commons.lang3.StringUtils
|
|
|
+import org.apache.spark.sql.SparkSession
|
|
|
+
|
|
|
+import scala.collection.mutable
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 司法拍卖两表合并
|
|
|
+ * @author π
|
|
|
+ * @date 2020/8/1115:35
|
|
|
+ */
|
|
|
+object CompanyJudicialSaleCombine {
|
|
|
+ def main(args: Array[String]): Unit = {
|
|
|
+ //winhc_eci_dev company_judicial_sale
|
|
|
+ val Array(project, tableName) = args
|
|
|
+ println(
|
|
|
+ s"""
|
|
|
+ |project: $project
|
|
|
+ |tableName: $tableName
|
|
|
+ |""".stripMargin)
|
|
|
+ if (args.length != 2) {
|
|
|
+ println("请输入 project:项目, tableName:表名 !!!")
|
|
|
+ sys.exit(-1)
|
|
|
+ }
|
|
|
+ val config = mutable.Map(
|
|
|
+ "spark.hadoop.odps.project.name" -> "winhc_eci_dev",
|
|
|
+ "spark.hadoop.odps.spark.local.partition.amt" -> "1"
|
|
|
+ )
|
|
|
+ val spark: SparkSession = SparkUtils.InitEnv(this.getClass.getSimpleName, config)
|
|
|
+ CompanyJudicialSaleCombine(spark,project,tableName).calc
|
|
|
+ spark.stop()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+case class CompanyJudicialSaleCombine(s: SparkSession,
|
|
|
+ project: String, //表所在工程名
|
|
|
+ tableName: String //表名(不加前后辍)
|
|
|
+ ) extends LoggingUtils with CompanyMapping{
|
|
|
+ override protected val spark: SparkSession = s
|
|
|
+
|
|
|
+ def calc ={
|
|
|
+
|
|
|
+ val inc_ods_v0 = s"${project}.inc_ods_${tableName}_item" //ods源表
|
|
|
+ val inc_ods_v1 = s"${project}.inc_ods_${tableName}_item" //ods源表
|
|
|
+ val inc_ods_v2 = s"${project}.inc_ods_${tableName}_combine" //ods合并表
|
|
|
+ //增量ods最新分区
|
|
|
+ val v0 = BaseUtil.getFirstPartion(inc_ods_v0, spark)
|
|
|
+ val v1 = BaseUtil.getPartion(inc_ods_v1, spark)
|
|
|
+ var v2 = BaseUtil.getPartion(inc_ods_v2, spark)
|
|
|
+ if(StringUtils.isBlank(v2)){
|
|
|
+ v2 = BaseUtil.atDaysAfter(-1, v0)
|
|
|
+ }
|
|
|
+
|
|
|
+ sql(
|
|
|
+ s"""
|
|
|
+ |INSERT OVERWRITE TABLE winhc_eci_dev.inc_ods_company_judicial_sale_combine PARTITION(ds='$v1')
|
|
|
+ |SELECT a.id
|
|
|
+ | ,a.main_id
|
|
|
+ | ,a.cids
|
|
|
+ | ,a.title AS name
|
|
|
+ | ,a.initial_price
|
|
|
+ | ,a.current_price
|
|
|
+ | ,a.consult_price
|
|
|
+ | ,a.start_time
|
|
|
+ | ,a.end_time
|
|
|
+ | ,a.pic_source_url
|
|
|
+ | ,a.pic_oss_url
|
|
|
+ | ,a.create_time
|
|
|
+ | ,a.update_time
|
|
|
+ | ,a.deleted
|
|
|
+ | ,b.title
|
|
|
+ | ,b.introduction
|
|
|
+ | ,b.court
|
|
|
+ | ,b.pub_time
|
|
|
+ | ,b.end_date
|
|
|
+ | ,b.content
|
|
|
+ | ,b.source_tag
|
|
|
+ | ,b.source_id
|
|
|
+ |FROM (
|
|
|
+ | SELECT *
|
|
|
+ | FROM (
|
|
|
+ | SELECT *
|
|
|
+ | ,ROW_NUMBER() OVER(PARTITION BY cids,main_id ORDER BY update_time DESC) num1
|
|
|
+ | FROM winhc_eci_dev.inc_ods_company_judicial_sale_item
|
|
|
+ | WHERE ds > $v2 AND ds <= $v1
|
|
|
+ | AND cids IS NOT NULL
|
|
|
+ | ) c
|
|
|
+ | WHERE num1 = 1
|
|
|
+ | ) a
|
|
|
+ |LEFT JOIN (
|
|
|
+ | SELECT *
|
|
|
+ | FROM (
|
|
|
+ | SELECT *
|
|
|
+ | ,ROW_NUMBER() OVER(PARTITION BY cids,title ORDER BY update_time DESC) num2
|
|
|
+ | FROM winhc_eci_dev.inc_ods_company_judicial_sale
|
|
|
+ | WHERE ds > $v2 AND ds <= $v1
|
|
|
+ | ) d
|
|
|
+ | WHERE num2 = 1
|
|
|
+ | ) b
|
|
|
+ |ON a.main_id = b.id
|
|
|
+ |WHERE b.id IS NOT NULL
|
|
|
+ |""".stripMargin)
|
|
|
+ }
|
|
|
+}
|