|
@@ -12,7 +12,7 @@ import scala.annotation.meta.getter
|
|
|
* cid转换
|
|
|
*/
|
|
|
|
|
|
-case class CompanyForCidUtils(s: SparkSession, space: String, sourceTable: String, cols: Seq[String]) extends LoggingUtils with CompanyMapping{
|
|
|
+case class CompanyForCidUtils(s: SparkSession, space: String, sourceTable: String, cols: Seq[String]) extends LoggingUtils with CompanyMapping {
|
|
|
@(transient@getter) val spark: SparkSession = s
|
|
|
|
|
|
val rowKeyMapping =
|
|
@@ -35,15 +35,16 @@ case class CompanyForCidUtils(s: SparkSession, space: String, sourceTable: Strin
|
|
|
//rowkey前缀匹配
|
|
|
val rowKeyPre = rowKeyMapping.getOrElse(sourceTable,"new_cid")
|
|
|
|
|
|
- val ddl = spark.table(odsTable).schema.filter(s=>{!"ds".equals(s.name)}).map(s=>{
|
|
|
-
|
|
|
+ val ddl = spark.table(odsTable).schema.filter(s => {
|
|
|
+ !"ds".equals(s.name)
|
|
|
+ }).map(s => {
|
|
|
val name = s.name
|
|
|
val dataType = s.dataType
|
|
|
s"$name ${DataTypeUtils.getDataType(dataType)} COMMENT '${s.getComment().getOrElse("")}'\n"
|
|
|
}).mkString(",")
|
|
|
|
|
|
|
|
|
- sql(
|
|
|
+ println(
|
|
|
s"""
|
|
|
|CREATE TABLE IF NOT EXISTS ${adsTable}
|
|
|
|(
|
|
@@ -54,6 +55,10 @@ case class CompanyForCidUtils(s: SparkSession, space: String, sourceTable: Strin
|
|
|
|COMMENT 'TABLE COMMENT'
|
|
|
|PARTITIONED BY (ds STRING COMMENT '分区')
|
|
|
|""".stripMargin)
|
|
|
+ if (!spark.catalog.tableExists("adsTable")) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//替换字段
|
|
|
sql(
|
|
@@ -78,12 +83,12 @@ case class CompanyForCidUtils(s: SparkSession, space: String, sourceTable: Strin
|
|
|
| ) d
|
|
|
|WHERE num =1 AND cols is not null AND trim(cols) <> ''
|
|
|
|""".stripMargin)
|
|
|
-// .createOrReplaceTempView(s"t2")
|
|
|
+ // .createOrReplaceTempView(s"t2")
|
|
|
|
|
|
-// sql(s"select rowkey,new_cid,${columns.mkString(",")} from t2").show(10)
|
|
|
+ // sql(s"select rowkey,new_cid,${columns.mkString(",")} from t2").show(10)
|
|
|
|
|
|
//写表
|
|
|
-// sql(s"insert into table ${adsTable} partition (ds=${ds}) select rowkey,new_cid,${columns.mkString(",")} from t2")
|
|
|
+ // sql(s"insert into table ${adsTable} partition (ds=${ds}) select rowkey,new_cid,${columns.mkString(",")} from t2")
|
|
|
|
|
|
println(s"${this.getClass.getSimpleName} calc end! " + new Date().toString)
|
|
|
}
|