@@ -31,6 +31,7 @@ db = pymysql.connect(host='172.16.40.158', port=4000, user='st_user', passwd='aq
...
@@ -31,6 +31,7 @@ db = pymysql.connect(host='172.16.40.158', port=4000, user='st_user', passwd='aq
db='jerry_prod')
db='jerry_prod')
cursor=db.cursor()
cursor=db.cursor()
defcon_sql(sql):
defcon_sql(sql):
# 从数据库的表里获取数据
# 从数据库的表里获取数据
...
@@ -78,17 +79,11 @@ spark.sql("CREATE TEMPORARY FUNCTION json_map AS 'brickhouse.udf.json.JsonMapUDF
...
@@ -78,17 +79,11 @@ spark.sql("CREATE TEMPORARY FUNCTION json_map AS 'brickhouse.udf.json.JsonMapUDF
spark.sql("CREATE TEMPORARY FUNCTION is_json AS 'com.gmei.hive.common.udf.UDFJsonFormatCheck'")
spark.sql("CREATE TEMPORARY FUNCTION is_json AS 'com.gmei.hive.common.udf.UDFJsonFormatCheck'")
spark.sql("CREATE TEMPORARY FUNCTION arrayMerge AS 'com.gmei.hive.common.udf.UDFArryMerge'")
spark.sql("CREATE TEMPORARY FUNCTION arrayMerge AS 'com.gmei.hive.common.udf.UDFArryMerge'")
ungrey_select_sql="""SELECT *,NVL(ROUND(wel_click_pv/wel_exp_pv,6),0) as meigou_ctr,
grey_select_sql="""SELECT *,NVL(ROUND((navbar_search+highlight_word+self_welfare_card+recommend_welfare_card+recommend_content_card*0.2+transfer_card+video_consultation)/card_exposure,5),0) as recommend_ctr,
NVL(ROUND(content_click_pv/content_exp_pv,6),0) as neirong_ctr FROM pm.tl_pm_contentpage_ctr where grey_type = '非灰'"""
NVL(ROUND(card_click/card_exposure,5),0) as click_ctr,
ungrey_df=spark.sql(ungrey_select_sql)
NVL(ROUND((navbar_search+highlight_word+self_welfare_card+recommend_welfare_card+recommend_content_card*0.2+transfer_card+video_consultation)/card_click,5),0) as second_jump_ctr, FROM pm.tl_pm_recommend_strategy_d"""
ungrey_df.createOrReplaceTempView("ungrey")
device_df=spark.sql(grey_select_sql)
grey_select_sql="""SELECT *,NVL(ROUND(wel_click_pv/wel_exp_pv,6),0) as grey_meigou_ctr,
NVL(ROUND(content_click_pv/content_exp_pv,6),0) as grey_neirong_ctr FROM pm.tl_pm_contentpage_ctr where grey_type = '灰度'"""
grey_df=spark.sql(grey_select_sql)
grey_df.createOrReplaceTempView("grey")
sql="""SELECT *,ungrey.meigou_ctr,ungrey.neirong_ctr from grey"""