|
@@ -189,4 +189,36 @@ trait LoggingUtils extends Logging {
|
|
|
projectName.substring(0, projectName.length - 4)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ def generateAllTabSql(tableName: String, project: String): (String, Seq[String],String) = {
|
|
|
+ val inc_ads_tab = s"$project.inc_ads_$tableName"
|
|
|
+ val ads_tab = s"$project.ads_$tableName"
|
|
|
+ val cols = getColumns(inc_ads_tab).intersect(getColumns(ads_tab))
|
|
|
+
|
|
|
+ val ads_last_ds = getLastPartitionsOrElse(ads_tab, null)
|
|
|
+ if (ads_last_ds == null) {
|
|
|
+ throw new RuntimeException(s"$ads_tab ds is null !")
|
|
|
+ }
|
|
|
+ val p_b = if (cols.contains("rowkey")) "rowkey" else if (cols.contains("company_id")) "company_id" else throw new RuntimeException(s"$ads_tab partition key is null !")
|
|
|
+
|
|
|
+ (
|
|
|
+ s"""
|
|
|
+ |SELECT ${cols.mkString(",")}
|
|
|
+ |FROM (
|
|
|
+ | SELECT *
|
|
|
+ | ,ROW_NUMBER() OVER(PARTITION BY $p_b ORDER BY ds DESC ) AS xjk_num
|
|
|
+ | FROM (
|
|
|
+ | SELECT ${cols.mkString(",")}
|
|
|
+ | FROM $ads_tab
|
|
|
+ | WHERE ds = $ads_last_ds
|
|
|
+ | UNION ALL
|
|
|
+ | SELECT ${cols.mkString(",")}
|
|
|
+ | FROM $inc_ads_tab
|
|
|
+ | WHERE ds > $ads_last_ds
|
|
|
+ | ) AS all_t1
|
|
|
+ | ) AS all_t2
|
|
|
+ |WHERE all_t2.xjk_num = 1
|
|
|
+ |""".stripMargin, cols,p_b)
|
|
|
+ }
|
|
|
}
|