|
@@ -70,51 +70,94 @@ object ChangeExtract {
|
|
|
sql(
|
|
|
s"""
|
|
|
|SELECT cid,current_cid as new_cid
|
|
|
- |FROM ${project}.inc_ods_company
|
|
|
- |WHERE ds > $lastDs_ads_all and ds < $ds
|
|
|
+ |FROM ${project}.inc_ads_company
|
|
|
+ |WHERE ds = $ds
|
|
|
|AND cid IS NOT NULL
|
|
|
|AND current_cid IS NOT NULL
|
|
|
|GROUP BY cid,current_cid
|
|
|
|""".stripMargin).createOrReplaceTempView("mapping")
|
|
|
|
|
|
val cid = getColumns(s"$project.ads_$tableName").filter(f => f.equals("cid") || f.equals("new_cid")).max
|
|
|
- df = sql(
|
|
|
- s"""
|
|
|
- |SELECT $primaryKey,${otherAllCols.mkString(",")},'0' as change_flag
|
|
|
- |FROM $project.inc_ads_$tableName
|
|
|
- |WHERE ds = $ds
|
|
|
- |UNION ALL
|
|
|
- |SELECT t2.$primaryKey,${otherAllCols.map("t2." + _).mkString(",")},'1' as change_flag
|
|
|
- |FROM (
|
|
|
- | SELECT DISTINCT ${primaryKey}
|
|
|
- | FROM $project.inc_ads_$tableName
|
|
|
- | WHERE ds = $ds
|
|
|
- | ) AS t1
|
|
|
- |JOIN (
|
|
|
- | SELECT concat_ws('_',coalesce(mm.new_cid,tmp.$cid),split(rowkey, '_')[1]) AS rowkey
|
|
|
- | ,${intersectCols.diff(Set("rowkey", "cid", "new_cid")).mkString(",")}
|
|
|
- | ,coalesce(mm.new_cid,tmp.$cid) AS new_cid
|
|
|
- | ,tmp.$cid as cid
|
|
|
- | ,c
|
|
|
- | FROM (
|
|
|
- | SELECT a.*
|
|
|
- | ,row_number() OVER (PARTITION BY a.${primaryKey} ORDER BY update_time DESC) c
|
|
|
- | FROM (
|
|
|
- | SELECT ${intersectCols.mkString(",")}
|
|
|
- | FROM $project.ads_$tableName
|
|
|
- | WHERE ds = $lastDs_ads_all
|
|
|
- | UNION ALL
|
|
|
- | SELECT ${intersectCols.mkString(",")}
|
|
|
- | FROM $project.inc_ads_$tableName
|
|
|
- | WHERE ds > $lastDs_ads_all and ds < $ds
|
|
|
- | ) AS a
|
|
|
- | ) AS tmp
|
|
|
- | LEFT JOIN mapping mm
|
|
|
- | ON tmp.$cid = mm.cid
|
|
|
- | WHERE tmp.c = 1
|
|
|
- | ) AS t2
|
|
|
- |ON t1.${primaryKey} = t2.${primaryKey}
|
|
|
- |""".stripMargin)
|
|
|
+
|
|
|
+ primaryKey.equals("rowkey") match {
|
|
|
+ case true => {
|
|
|
+ df = sql(
|
|
|
+ s"""
|
|
|
+ |SELECT $primaryKey,${otherAllCols.mkString(",")},'0' as change_flag
|
|
|
+ |FROM $project.inc_ads_$tableName
|
|
|
+ |WHERE ds = $ds
|
|
|
+ |UNION ALL
|
|
|
+ |SELECT t2.$primaryKey,${otherAllCols.map("t2." + _).mkString(",")},'1' as change_flag
|
|
|
+ |FROM (
|
|
|
+ | SELECT DISTINCT ${primaryKey}
|
|
|
+ | FROM $project.inc_ads_$tableName
|
|
|
+ | WHERE ds = $ds
|
|
|
+ | ) AS t1
|
|
|
+ |JOIN (
|
|
|
+ | SELECT concat_ws('_',coalesce(mm.new_cid,tmp.$cid),split(rowkey, '_')[1]) AS rowkey
|
|
|
+ | ,${intersectCols.diff(Set("rowkey", "cid", "new_cid")).mkString(",")}
|
|
|
+ | ,coalesce(mm.new_cid,tmp.$cid) AS new_cid
|
|
|
+ | ,tmp.$cid as cid
|
|
|
+ | ,c
|
|
|
+ | FROM (
|
|
|
+ | SELECT a.*
|
|
|
+ | ,row_number() OVER (PARTITION BY a.${primaryKey} ORDER BY update_time DESC) c
|
|
|
+ | FROM (
|
|
|
+ | SELECT ${intersectCols.mkString(",")}
|
|
|
+ | FROM $project.ads_$tableName
|
|
|
+ | WHERE ds = $lastDs_ads_all
|
|
|
+ | UNION ALL
|
|
|
+ | SELECT ${intersectCols.mkString(",")}
|
|
|
+ | FROM $project.inc_ads_$tableName
|
|
|
+ | WHERE ds > $lastDs_ads_all and ds < $ds
|
|
|
+ | ) AS a
|
|
|
+ | ) AS tmp
|
|
|
+ | LEFT JOIN mapping mm
|
|
|
+ | ON tmp.$cid = mm.cid
|
|
|
+ | WHERE tmp.c = 1
|
|
|
+ | ) AS t2
|
|
|
+ |ON t1.${primaryKey} = t2.${primaryKey}
|
|
|
+ |""".stripMargin)
|
|
|
+ }
|
|
|
+ case false => {
|
|
|
+ df = sql(
|
|
|
+ s"""
|
|
|
+ |SELECT $primaryKey,${otherAllCols.mkString(",")},'0' as change_flag
|
|
|
+ |FROM $project.inc_ads_$tableName
|
|
|
+ |WHERE ds = $ds
|
|
|
+ |UNION ALL
|
|
|
+ |SELECT t2.$primaryKey,${otherAllCols.map("t2." + _).mkString(",")},'1' as change_flag
|
|
|
+ |FROM (
|
|
|
+ | SELECT DISTINCT ${primaryKey}
|
|
|
+ | FROM $project.inc_ads_$tableName
|
|
|
+ | WHERE ds = $ds
|
|
|
+ | ) AS t1
|
|
|
+ |JOIN (
|
|
|
+ | SELECT ${intersectCols.diff(Set("rowkey", cid)).mkString(",")}
|
|
|
+ | ,coalesce(mm.new_cid,tmp.$cid) AS $cid
|
|
|
+ | FROM (
|
|
|
+ | SELECT a.*
|
|
|
+ | ,row_number() OVER (PARTITION BY a.${primaryKey} ORDER BY update_time DESC) c
|
|
|
+ | FROM (
|
|
|
+ | SELECT ${intersectCols.mkString(",")}
|
|
|
+ | FROM $project.ads_$tableName
|
|
|
+ | WHERE ds = $lastDs_ads_all
|
|
|
+ | UNION ALL
|
|
|
+ | SELECT ${intersectCols.mkString(",")}
|
|
|
+ | FROM $project.inc_ads_$tableName
|
|
|
+ | WHERE ds > $lastDs_ads_all and ds < $ds
|
|
|
+ | ) AS a
|
|
|
+ | ) AS tmp
|
|
|
+ | LEFT JOIN mapping mm
|
|
|
+ | ON tmp.$cid = mm.cid
|
|
|
+ | WHERE tmp.c = 1
|
|
|
+ | ) AS t2
|
|
|
+ |ON t1.${primaryKey} = t2.${primaryKey}
|
|
|
+ |""".stripMargin)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
case false => {
|
|
|
df = sql(
|
|
@@ -254,7 +297,7 @@ object ChangeExtract {
|
|
|
, Args(tableName = "company_icp", primaryFields = "domain")
|
|
|
, Args(tableName = "company_punishment_info", primaryFields = "punish_number")
|
|
|
, Args(tableName = "company_punishment_info_creditchina", primaryFields = "punish_number")
|
|
|
- , Args(tableName = "bankruptcy_open_case", primaryFields = "case_no")//破产重整
|
|
|
+ , Args(tableName = "bankruptcy_open_case", primaryFields = "case_no") //破产重整
|
|
|
, Args(tableName = "company_public_announcement2_list", primaryFields = "applicant_cid,owner_cid,drawer_cid,gather_name_cid,bill_num")//公示催告
|
|
|
|
|
|
, Args(tableName = "company_certificate", primaryFields = "type")
|
|
@@ -264,7 +307,8 @@ object ChangeExtract {
|
|
|
|
|
|
, Args(tableName = "company_equity_info", primaryKey = "id", primaryFields = "reg_number", isCopy = false)
|
|
|
, Args(tableName = "company_staff", primaryFields = "staff_type")
|
|
|
-
|
|
|
+ //公司名称,法人ID:人标识或公司标识,公司类型,注册地址,营业期限终止日期,经营范围,登记机关,企业状态 ,注册资本,实收资本金额(单位:分),注销日期,注销原因
|
|
|
+ , Args(tableName = "company", primaryKey = "cid", primaryFields = "name,legal_entity_id,company_org_type,reg_location,to_time,business_scope,reg_institute,reg_status,reg_capital,actual_capital_amount,cancel_date,cancel_reason")
|
|
|
)
|
|
|
|
|
|
private case class Args(project: String = "winhc_eci_dev"
|