|
@@ -24,8 +24,8 @@ object CompanyDynamic {
|
|
|
|
|
|
case class CompanyDynamicUtil(s: SparkSession,
|
|
|
project: String, //表所在工程名
|
|
|
- ds: String, //此维度主键
|
|
|
- bName: Boolean = false //是否补充cname字段
|
|
|
+ ds: String //此维度主键
|
|
|
+
|
|
|
) extends LoggingUtils with Logging {
|
|
|
@(transient@getter) val spark: SparkSession = s
|
|
|
|
|
@@ -56,7 +56,9 @@ object CompanyDynamic {
|
|
|
}
|
|
|
|
|
|
//表名(不加前后辍)
|
|
|
- def calc(tableName: String): Unit = {
|
|
|
+ def calc(tableName: String
|
|
|
+ , bName: Boolean = false //是否补充cname字段
|
|
|
+ ): Unit = {
|
|
|
val handle = getClazz[CompanyDynamicHandle](s"com.winhc.bigdata.spark.jobs.dynamic.tables.$tableName")
|
|
|
|
|
|
val types = handle.org_type()
|
|
@@ -65,7 +67,7 @@ object CompanyDynamic {
|
|
|
case false =>
|
|
|
s"""
|
|
|
|SELECT *,null AS cname
|
|
|
- |FROM ${getEnvProjectName(env, project)}.ads_change_extract
|
|
|
+ |FROM ${project}.ads_change_extract
|
|
|
|WHERE ds = '$ds'
|
|
|
|AND tn = '$tableName'
|
|
|
|AND TYPE in (${types.map("'" + _ + "'").mkString(",")})
|
|
@@ -75,14 +77,14 @@ object CompanyDynamic {
|
|
|
|SELECT A.*,B.cname AS cname
|
|
|
|FROM(
|
|
|
| SELECT *
|
|
|
- | FROM ${getEnvProjectName(env, project)}.ads_change_extract
|
|
|
+ | FROM ${project}.ads_change_extract
|
|
|
| WHERE ds = '$ds'
|
|
|
| AND tn = '$tableName'
|
|
|
| AND TYPE in (${types.map("'" + _ + "'").mkString(",")})
|
|
|
|) AS A
|
|
|
|LEFT JOIN (
|
|
|
- | SELECT cid,cname FROM ${getEnvProjectName(env, project)}.base_company_mapping
|
|
|
- | WHERE ds=(SELECT MAX(ds) FROM ${getEnvProjectName(env, project)}.base_company_mapping WHERE ds>'0')
|
|
|
+ | SELECT cid,cname FROM $project.base_company_mapping
|
|
|
+ | WHERE ds = '${getLastPartitionsOrElse(project + "base_company_mapping", "0")}'
|
|
|
|) AS B
|
|
|
|ON A.cid = B.cid
|
|
|
|""".stripMargin
|
|
@@ -134,7 +136,16 @@ object CompanyDynamic {
|
|
|
|
|
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
|
- val Array(project, tableName, ds, bName) = if (args.length >= 4) args else args :+ "false"
|
|
|
+ if (args.length < 3 || args.length > 4) {
|
|
|
+ println(
|
|
|
+ s"""
|
|
|
+ |Please enter the legal parameters !
|
|
|
+ |<project> <ds> <tableNames> [cname_tableNames]
|
|
|
+ |""".stripMargin)
|
|
|
+ sys.exit(-99)
|
|
|
+ }
|
|
|
+
|
|
|
+ val Array(project, ds, tableName, bName_table) = if (args.length == 4) args else args :+ ""
|
|
|
|
|
|
println(
|
|
|
s"""
|
|
@@ -148,13 +159,17 @@ object CompanyDynamic {
|
|
|
"spark.hadoop.odps.spark.local.partition.amt" -> "10"
|
|
|
)
|
|
|
val spark = SparkUtils.InitEnv("CompanyDynamic", config)
|
|
|
- val cd = CompanyDynamicUtil(spark, project, ds, bName.toBoolean)
|
|
|
+ val cd = CompanyDynamicUtil(spark, project, ds)
|
|
|
|
|
|
cd.init()
|
|
|
|
|
|
for (e <- tableName.split(",")) {
|
|
|
cd.calc(e)
|
|
|
}
|
|
|
+
|
|
|
+ for (e <- bName_table.split(",")) {
|
|
|
+ cd.calc(e, bName = true)
|
|
|
+ }
|
|
|
spark.stop()
|
|
|
}
|
|
|
}
|