Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
bi-report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data
bi-report
Commits
a47201ed
Commit
a47201ed
authored
Apr 24, 2020
by
赵建伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update codes
parent
b364c0c6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
118 deletions
+121
-118
demo.zip
jobs/demo/demo.zip
+0
-0
sparksql2email.sh
lib/shell/sparksql2email.sh
+7
-4
demo.sql
sqls/demo.sql
+96
-18
demo_bak.sql
sqls/demo_bak.sql
+18
-0
demo_param.sql
sqls/demo_param.sql
+0
-96
No files found.
jobs/demo/demo.zip
View file @
a47201ed
No preview for this file type
lib/shell/sparksql2email.sh
View file @
a47201ed
...
...
@@ -10,8 +10,10 @@ fi
#默认取输入的账期
V_DATE
=
$4
partition_date
=
`
date
+
"%Y%m%d"
`
timestamp
=
`
date
+
"%Y%m%d%H%M%S"
`
tmp_file_name
=
"/data/bi-report/tmp/tmp_"
$timestamp
".sql"
result_file_name
=
"/data/bi-report/result/"
$1
"_"
$partition_date
".csv"
#输入的账期为空,则取T+1默认账期
if
[
-z
${
V_DATE
}
]
;
then
...
...
@@ -43,7 +45,7 @@ echo "V_7DAY_M_D_AGO: "$V_7DAY_M_D_AGO
echo
"************************************"
echo
""
cp
$1
$tmp_file_name
cp
"/srv/apps/bi-report/sqls/"
$1
".sql"
$tmp_file_name
sed
-i
"s/
\$
V_PARYMD/
$V_PARYMD
/g"
$tmp_file_name
sed
-i
"s/
\$
V_PARY_M_D/
$V_PARY_M_D
/g"
$tmp_file_name
sed
-i
"s/
\$
V_1DAYMD_AGO/
$V_1DAYMD_AGO
/g"
$tmp_file_name
...
...
@@ -52,15 +54,15 @@ sed -i "s/\$V_1DAY_M_D_AGO/$V_1DAY_M_D_AGO/g" $tmp_file_name
sed
-i
"s/
\$
V_7DAY_M_D_AGO/
$V_7DAY_M_D_AGO
/g"
$tmp_file_name
# 新标签与新标签对应集合类型 的对应关系
/opt/spark/spark-2.4.5-bin-hadoop2.7/bin/beeline
-u
jdbc:hive2://bj-gm-prod-cos-datacenter003:10010/online
-n
data
--outputformat
=
csv2
--showHeader
=
true
-e
"
`
cat
$tmp_file_name
`
"
>
"/data/bi-report/result/"
$2
".csv"
/opt/spark/spark-2.4.5-bin-hadoop2.7/bin/beeline
-u
jdbc:hive2://bj-gm-prod-cos-datacenter003:10010/online
-n
data
--outputformat
=
csv2
--showHeader
=
true
-e
"
`
cat
$tmp_file_name
`
"
>
$result_file_name
rm
-rf
$tmp_file_name
to
=
$2
cc
=
$3
echo
"to: "
$to
echo
"cc: "
$cc
python2.7 /srv/apps/bi-report/lib/python/sendmail.py
-t
$to
-s
自动发送
-m
$cc
-a
"/data/bi-report/result/"
$2
".csv"
python2.7 /srv/apps/bi-report/lib/python/sendmail.py
-t
$to
-s
自动发送
-m
$cc
-a
$result_file_name
exit
0
\ No newline at end of file
sqls/demo.sql
View file @
a47201ed
SELECT
partition_date
,
device_os_type
AS
device_type
,
CASE
WHEN
active_type
=
'4'
THEN
'老活'
WHEN
active_type
IN
(
'1'
,
'2'
)
THEN
'新增'
END
AS
active_type
,
device_id
FROM
online
.
ml_device_day_active_status
WHERE
partition_date
between
'20200401'
and
'20200408'
AND
active_type
IN
(
'1'
,
'2'
,
'4'
)
AND
first_channel_source_type
not
IN
(
'yqxiu1'
,
'yqxiu2'
,
'yqxiu3'
,
'yqxiu4'
,
'yqxiu5'
,
'mxyc1'
,
'mxyc2'
,
'mxyc3'
,
'wanpu'
,
'jinshan'
,
'jx'
,
'maimai'
,
'zhuoyi'
,
'huatian'
,
'suopingjingling'
,
'mocha'
,
'mizhe'
,
'meika'
,
'lamabang'
,
'js-az1'
,
'js-az2'
,
'js-az3'
,
'js-az4'
,
'js-az5'
,
'jfq-az1'
,
'jfq-az2'
,
'jfq-az3'
,
'jfq-az4'
,
'jfq-az5'
,
'toufang1'
,
'toufang2'
,
'toufang3'
,
'toufang4'
,
'toufang5'
,
'toufang6'
,
'TF-toufang1'
,
'TF-toufang2'
,
'TF-toufang3'
,
'TF-toufang4'
,
'TF-toufang5'
,
'tf-toufang1'
,
'tf-toufang2'
,
'tf-toufang3'
,
'tf-toufang4'
,
'tf-toufang5'
,
'benzhan'
,
'promotion_aso100'
,
'promotion_qianka'
,
'promotion_xiaoyu'
,
'promotion_dianru'
,
'promotion_malioaso'
,
'promotion_malioaso-shequ'
,
'promotion_shike'
,
'promotion_julang_jl03'
,
'promotion_zuimei'
)
AND
first_channel_source_type
not
LIKE
'promotion
\_
jf
\_
%'
limit
10
\ No newline at end of file
select
t6
.
new_tag_name
,
--新标签name
t6
.
new_tag_type
,
--新标签type
t6
.
new_tag_id
,
--新标签id
t6
.
is_display
,
--是否在app展示
t6
.
is_online
,
--是否生效
collect_set
(
t6
.
jianyi_word
)
as
jianyi_word
,
--近义词
collect_set
(
t6
.
like_new_tag
)
as
tongyi_word
,
--同义词
collect_set
(
t6
.
fangshi_1f
)
as
fangshi_1st
,
--一级方式_name
collect_set
(
t6
.
fangshi_2d
)
as
fangshi_2nd
,
--二级方式_name
collect_set
(
t6
.
suqiu_1f
)
as
suqiu_1st
,
--一级诉求_name
collect_set
(
t6
.
suqiu_2d
)
as
suqiu_2nd
,
--二级诉求_name
collect_set
(
t6
.
buwei_if
)
as
buwei_1st
,
--一级部位_name
collect_set
(
t6
.
buwei_2d
)
as
buwei_2nd
,
--二级部位_name
collect_set
(
t6
.
old_tag_name
)
as
old_tag_name
,
--老标签_name
collect_set
(
t6
.
old_tag_type
)
as
old_tag_type
,
--老标签_type
collect_set
(
t6
.
old_tag_id
)
as
old_tag_id
,
--老标签_id
collect_set
(
t6
.
fangshi_1f_id
)
as
fangshi_1st_id
,
--一级方式_id
collect_set
(
t6
.
fangshi_2d_id
)
as
fangshi_2nd_id
,
--二级方式_id
collect_set
(
t6
.
suqiu_1f_id
)
as
suqiu_1st_id
,
--一级诉求_id
collect_set
(
t6
.
suqiu_2d_id
)
as
suqiu_2nd_id
,
--二级诉求_id
collect_set
(
t6
.
buwei_if_id
)
as
buwei_1st_id
,
--一级部位_id
collect_set
(
t6
.
buwei_2d_id
)
as
buwei_2nd_id
--二级部位_id
from
(
select
t1
.
name
as
new_tag_name
,
--新标签name
t1
.
tag_type
as
new_tag_type
,
--新标签type
t1
.
id
as
new_tag_id
,
--新标签id
t1
.
is_display
as
is_display
,
--是否在app展示
t1
.
is_online
as
is_online
,
--是否生效
t1
.
homoionym
as
jianyi_word
,
--近义词
t2
.
name
as
like_new_tag
,
--同义词
t4
.
aggregate_type
,
--对应类型的枚举值
(
case
when
t4
.
aggregate_type
=
'6'
then
t4
.
name
else
NULL
end
)
as
fangshi_1f
,
--一级方式_name
(
case
when
t4
.
aggregate_type
=
'2'
then
t4
.
name
else
NULL
end
)
as
fangshi_2d
,
--二级方式_name
(
case
when
t4
.
aggregate_type
=
'7'
then
t4
.
name
else
NULL
end
)
as
suqiu_1f
,
--一级诉求_name
(
case
when
t4
.
aggregate_type
=
'8'
then
t4
.
name
else
NULL
end
)
as
suqiu_2d
,
--二级诉求_name
(
case
when
t4
.
aggregate_type
=
'10'
then
t4
.
name
else
NULL
end
)
as
buwei_if
,
--一级部位_name
(
case
when
t4
.
aggregate_type
=
'3'
then
t4
.
name
else
NULL
end
)
as
buwei_2d
,
--二级部位_name
t7
.
old_tag_name
as
old_tag_name
,
--老标签_name
t7
.
old_tag_type
as
old_tag_type
,
--老标签_type
t5
.
old_tag_id
as
old_tag_id
,
--老标签_id
(
case
when
t4
.
aggregate_type
=
'6'
then
t4
.
id
else
NULL
end
)
as
fangshi_1f_id
,
--一级方式_id
(
case
when
t4
.
aggregate_type
=
'2'
then
t4
.
id
else
NULL
end
)
as
fangshi_2d_id
,
--二级方式_id
(
case
when
t4
.
aggregate_type
=
'7'
then
t4
.
id
else
NULL
end
)
as
suqiu_1f_id
,
--一级诉求_id
(
case
when
t4
.
aggregate_type
=
'8'
then
t4
.
id
else
NULL
end
)
as
suqiu_2d_id
,
--二级诉求_id
(
case
when
t4
.
aggregate_type
=
'10'
then
t4
.
id
else
NULL
end
)
as
buwei_if_id
,
--一级部位_id
(
case
when
t4
.
aggregate_type
=
'3'
then
t4
.
id
else
NULL
end
)
as
buwei_2d_id
--二级部位_id
from
(
select
name
,
id
,
is_display
,
is_online
,
case
when
tag_type
in
(
'1'
)
then
'普通分类'
when
tag_type
in
(
'2'
)
then
'一级分类'
when
tag_type
in
(
'3'
)
then
'二级分类'
end
as
tag_type
,
collect_list
(
t1
.
homoionym_detail
)
as
homoionym
from
online
.
tl_hdfs_api_tag_3_0_view
--新标签id,近义词
lateral
view
explode
(
json_split
(
homoionym
))
t1
as
homoionym_detail
--["\u8138\u578b\u77eb\u6b63"]转义 json_split
where
partition_date
=
'$V_PARYMD'
group
by
name
,
id
,
is_display
,
is_online
,
case
when
tag_type
in
(
'1'
)
then
'普通分类'
when
tag_type
in
(
'2'
)
then
'一级分类'
when
tag_type
in
(
'3'
)
then
'二级分类'
end
)
t1
left
join
(
select
name
,
tag_id
from
online
.
tl_hdfs_api_tag_aggregate_view
where
partition_date
=
'$V_PARYMD'
)
t2
--新标签id,同义词
on
(
t1
.
id
=
t2
.
tag_id
)
left
join
(
select
tag_attr_id
as
tag_ids
,
tag_id
from
online
.
tl_hdfs_api_tag_attr_tag_view
where
partition_date
=
'$V_PARYMD'
)
t3
--新标签id,属性ids
on
(
t1
.
id
=
t3
.
tag_id
)
left
join
(
select
name
,
id
,
aggregate_type
from
online
.
tl_hdfs_api_tag_attr_view
where
partition_date
=
'$V_PARYMD'
)
t4
--属性id,属性分类
on
(
t3
.
tag_ids
=
t4
.
id
)
left
join
(
select
old_tag_id
,
tag_id
from
online
.
tl_hdfs_api_tag_map_oldtag_view
where
partition_date
=
'$V_PARYMD'
)
t5
on
(
t1
.
id
=
t5
.
tag_id
)
left
join
(
select
id
,
name
as
old_tag_name
,
case
when
tag_type
in
(
'1'
)
then
'一级分类'
when
tag_type
in
(
'2'
)
then
'二级分类'
when
tag_type
in
(
'3'
)
then
'三级分类'
when
tag_type
in
(
'4'
)
then
'城市'
when
tag_type
in
(
'5'
)
then
'自由添加'
when
tag_type
in
(
'6'
)
then
'医生'
when
tag_type
in
(
'7'
)
then
'医院'
when
tag_type
in
(
'8'
)
then
'频道'
when
tag_type
in
(
'9'
)
then
'省份'
when
tag_type
in
(
'10'
)
then
'国家'
when
tag_type
in
(
'11'
)
then
'运营标签'
end
as
old_tag_type
from
online
.
tl_hdfs_api_tag_view
where
partition_date
=
'$V_PARYMD'
)
t7
on
(
t7
.
id
=
t5
.
old_tag_id
)
)
t6
group
by
t6
.
new_tag_name
,
t6
.
new_tag_type
,
t6
.
new_tag_id
,
t6
.
is_display
,
t6
.
is_online
\ No newline at end of file
sqls/demo_bak.sql
0 → 100644
View file @
a47201ed
SELECT
partition_date
,
device_os_type
AS
device_type
,
CASE
WHEN
active_type
=
'4'
THEN
'老活'
WHEN
active_type
IN
(
'1'
,
'2'
)
THEN
'新增'
END
AS
active_type
,
device_id
FROM
online
.
ml_device_day_active_status
WHERE
partition_date
between
'20200401'
and
'20200408'
AND
active_type
IN
(
'1'
,
'2'
,
'4'
)
AND
first_channel_source_type
not
IN
(
'yqxiu1'
,
'yqxiu2'
,
'yqxiu3'
,
'yqxiu4'
,
'yqxiu5'
,
'mxyc1'
,
'mxyc2'
,
'mxyc3'
,
'wanpu'
,
'jinshan'
,
'jx'
,
'maimai'
,
'zhuoyi'
,
'huatian'
,
'suopingjingling'
,
'mocha'
,
'mizhe'
,
'meika'
,
'lamabang'
,
'js-az1'
,
'js-az2'
,
'js-az3'
,
'js-az4'
,
'js-az5'
,
'jfq-az1'
,
'jfq-az2'
,
'jfq-az3'
,
'jfq-az4'
,
'jfq-az5'
,
'toufang1'
,
'toufang2'
,
'toufang3'
,
'toufang4'
,
'toufang5'
,
'toufang6'
,
'TF-toufang1'
,
'TF-toufang2'
,
'TF-toufang3'
,
'TF-toufang4'
,
'TF-toufang5'
,
'tf-toufang1'
,
'tf-toufang2'
,
'tf-toufang3'
,
'tf-toufang4'
,
'tf-toufang5'
,
'benzhan'
,
'promotion_aso100'
,
'promotion_qianka'
,
'promotion_xiaoyu'
,
'promotion_dianru'
,
'promotion_malioaso'
,
'promotion_malioaso-shequ'
,
'promotion_shike'
,
'promotion_julang_jl03'
,
'promotion_zuimei'
)
AND
first_channel_source_type
not
LIKE
'promotion
\_
jf
\_
%'
limit
10
\ No newline at end of file
sqls/demo_param.sql
deleted
100644 → 0
View file @
b364c0c6
select
t6
.
new_tag_name
,
--新标签name
t6
.
new_tag_type
,
--新标签type
t6
.
new_tag_id
,
--新标签id
t6
.
is_display
,
--是否在app展示
t6
.
is_online
,
--是否生效
collect_set
(
t6
.
jianyi_word
)
as
jianyi_word
,
--近义词
collect_set
(
t6
.
like_new_tag
)
as
tongyi_word
,
--同义词
collect_set
(
t6
.
fangshi_1f
)
as
fangshi_1st
,
--一级方式_name
collect_set
(
t6
.
fangshi_2d
)
as
fangshi_2nd
,
--二级方式_name
collect_set
(
t6
.
suqiu_1f
)
as
suqiu_1st
,
--一级诉求_name
collect_set
(
t6
.
suqiu_2d
)
as
suqiu_2nd
,
--二级诉求_name
collect_set
(
t6
.
buwei_if
)
as
buwei_1st
,
--一级部位_name
collect_set
(
t6
.
buwei_2d
)
as
buwei_2nd
,
--二级部位_name
collect_set
(
t6
.
old_tag_name
)
as
old_tag_name
,
--老标签_name
collect_set
(
t6
.
old_tag_type
)
as
old_tag_type
,
--老标签_type
collect_set
(
t6
.
old_tag_id
)
as
old_tag_id
,
--老标签_id
collect_set
(
t6
.
fangshi_1f_id
)
as
fangshi_1st_id
,
--一级方式_id
collect_set
(
t6
.
fangshi_2d_id
)
as
fangshi_2nd_id
,
--二级方式_id
collect_set
(
t6
.
suqiu_1f_id
)
as
suqiu_1st_id
,
--一级诉求_id
collect_set
(
t6
.
suqiu_2d_id
)
as
suqiu_2nd_id
,
--二级诉求_id
collect_set
(
t6
.
buwei_if_id
)
as
buwei_1st_id
,
--一级部位_id
collect_set
(
t6
.
buwei_2d_id
)
as
buwei_2nd_id
--二级部位_id
from
(
select
t1
.
name
as
new_tag_name
,
--新标签name
t1
.
tag_type
as
new_tag_type
,
--新标签type
t1
.
id
as
new_tag_id
,
--新标签id
t1
.
is_display
as
is_display
,
--是否在app展示
t1
.
is_online
as
is_online
,
--是否生效
t1
.
homoionym
as
jianyi_word
,
--近义词
t2
.
name
as
like_new_tag
,
--同义词
t4
.
aggregate_type
,
--对应类型的枚举值
(
case
when
t4
.
aggregate_type
=
'6'
then
t4
.
name
else
NULL
end
)
as
fangshi_1f
,
--一级方式_name
(
case
when
t4
.
aggregate_type
=
'2'
then
t4
.
name
else
NULL
end
)
as
fangshi_2d
,
--二级方式_name
(
case
when
t4
.
aggregate_type
=
'7'
then
t4
.
name
else
NULL
end
)
as
suqiu_1f
,
--一级诉求_name
(
case
when
t4
.
aggregate_type
=
'8'
then
t4
.
name
else
NULL
end
)
as
suqiu_2d
,
--二级诉求_name
(
case
when
t4
.
aggregate_type
=
'10'
then
t4
.
name
else
NULL
end
)
as
buwei_if
,
--一级部位_name
(
case
when
t4
.
aggregate_type
=
'3'
then
t4
.
name
else
NULL
end
)
as
buwei_2d
,
--二级部位_name
t7
.
old_tag_name
as
old_tag_name
,
--老标签_name
t7
.
old_tag_type
as
old_tag_type
,
--老标签_type
t5
.
old_tag_id
as
old_tag_id
,
--老标签_id
(
case
when
t4
.
aggregate_type
=
'6'
then
t4
.
id
else
NULL
end
)
as
fangshi_1f_id
,
--一级方式_id
(
case
when
t4
.
aggregate_type
=
'2'
then
t4
.
id
else
NULL
end
)
as
fangshi_2d_id
,
--二级方式_id
(
case
when
t4
.
aggregate_type
=
'7'
then
t4
.
id
else
NULL
end
)
as
suqiu_1f_id
,
--一级诉求_id
(
case
when
t4
.
aggregate_type
=
'8'
then
t4
.
id
else
NULL
end
)
as
suqiu_2d_id
,
--二级诉求_id
(
case
when
t4
.
aggregate_type
=
'10'
then
t4
.
id
else
NULL
end
)
as
buwei_if_id
,
--一级部位_id
(
case
when
t4
.
aggregate_type
=
'3'
then
t4
.
id
else
NULL
end
)
as
buwei_2d_id
--二级部位_id
from
(
select
name
,
id
,
is_display
,
is_online
,
case
when
tag_type
in
(
'1'
)
then
'普通分类'
when
tag_type
in
(
'2'
)
then
'一级分类'
when
tag_type
in
(
'3'
)
then
'二级分类'
end
as
tag_type
,
collect_list
(
t1
.
homoionym_detail
)
as
homoionym
from
online
.
tl_hdfs_api_tag_3_0_view
--新标签id,近义词
lateral
view
explode
(
json_split
(
homoionym
))
t1
as
homoionym_detail
--["\u8138\u578b\u77eb\u6b63"]转义 json_split
where
partition_date
=
'$V_PARYMD'
group
by
name
,
id
,
is_display
,
is_online
,
case
when
tag_type
in
(
'1'
)
then
'普通分类'
when
tag_type
in
(
'2'
)
then
'一级分类'
when
tag_type
in
(
'3'
)
then
'二级分类'
end
)
t1
left
join
(
select
name
,
tag_id
from
online
.
tl_hdfs_api_tag_aggregate_view
where
partition_date
=
'$V_PARYMD'
)
t2
--新标签id,同义词
on
(
t1
.
id
=
t2
.
tag_id
)
left
join
(
select
tag_attr_id
as
tag_ids
,
tag_id
from
online
.
tl_hdfs_api_tag_attr_tag_view
where
partition_date
=
'$V_PARYMD'
)
t3
--新标签id,属性ids
on
(
t1
.
id
=
t3
.
tag_id
)
left
join
(
select
name
,
id
,
aggregate_type
from
online
.
tl_hdfs_api_tag_attr_view
where
partition_date
=
'$V_PARYMD'
)
t4
--属性id,属性分类
on
(
t3
.
tag_ids
=
t4
.
id
)
left
join
(
select
old_tag_id
,
tag_id
from
online
.
tl_hdfs_api_tag_map_oldtag_view
where
partition_date
=
'$V_PARYMD'
)
t5
on
(
t1
.
id
=
t5
.
tag_id
)
left
join
(
select
id
,
name
as
old_tag_name
,
case
when
tag_type
in
(
'1'
)
then
'一级分类'
when
tag_type
in
(
'2'
)
then
'二级分类'
when
tag_type
in
(
'3'
)
then
'三级分类'
when
tag_type
in
(
'4'
)
then
'城市'
when
tag_type
in
(
'5'
)
then
'自由添加'
when
tag_type
in
(
'6'
)
then
'医生'
when
tag_type
in
(
'7'
)
then
'医院'
when
tag_type
in
(
'8'
)
then
'频道'
when
tag_type
in
(
'9'
)
then
'省份'
when
tag_type
in
(
'10'
)
then
'国家'
when
tag_type
in
(
'11'
)
then
'运营标签'
end
as
old_tag_type
from
online
.
tl_hdfs_api_tag_view
where
partition_date
=
'$V_PARYMD'
)
t7
on
(
t7
.
id
=
t5
.
old_tag_id
)
)
t6
group
by
t6
.
new_tag_name
,
t6
.
new_tag_type
,
t6
.
new_tag_id
,
t6
.
is_display
,
t6
.
is_online
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment