dnet-hadoop/dhp-workflows/dhp-indicators/src/main/resources/eu/dnetlib/dhp/oa/graph/indicators/oozie_app/scripts/createIndicatorsTablesSprin...

198 lines
8.8 KiB
SQL

create table TARGET.indi_pub_avg_year_country_oa stored as parquet as
select year, country, round(OpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentOA,
round(NonOpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentNonOA
from
(SELECT year, country, SUM(CASE
WHEN bestlicence='Open Access' THEN 1
ELSE 0
END) AS OpenAccess, SUM(CASE
WHEN bestlicence<>'Open Access' THEN 1
ELSE 0
END) AS NonOpenAccess
FROM SOURCE.publication p
join SOURCE.result_organization ro on p.id=ro.id
join SOURCE.organization o on o.id=ro.organization
where cast(year as int)>=2003 and cast(year as int)<=2021
group by year, country) tmp
create table TARGET.indi_dataset_avg_year_country_oa stored as parquet as
select year, country, round(OpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentOA,
round(NonOpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentNonOA
from
(SELECT year, country, SUM(CASE
WHEN bestlicence='Open Access' THEN 1
ELSE 0
END) AS OpenAccess, SUM(CASE
WHEN bestlicence<>'Open Access' THEN 1
ELSE 0
END) AS NonOpenAccess
FROM SOURCE.dataset d
join SOURCE.result_organization ro on d.id=ro.id
join SOURCE.organization o on o.id=ro.organization
where cast(year as int)>=2003 and cast(year as int)<=2021
group by year, country) tmp
create table TARGET.indi_software_avg_year_country_oa stored as parquet as
select year, country, round(OpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentOA,
round(NonOpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentNonOA
from
(SELECT year, country, SUM(CASE
WHEN bestlicence='Open Access' THEN 1
ELSE 0
END) AS OpenAccess, SUM(CASE
WHEN bestlicence<>'Open Access' THEN 1
ELSE 0
END) AS NonOpenAccess
FROM SOURCE.software s
join SOURCE.result_organization ro on s.id=ro.id
join SOURCER.organization o on o.id=ro.organization
where cast(year as int)>=2003 and cast(year as int)<=2021
group by year, country) tmp
create table TARGET.indi_other_avg_year_country_oa stored as parquet as
select year, country, round(OpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentOA,
round(NonOpenAccess/(OpenAccess+NonOpenAccess)*100,3) as percentNonOA
from
(SELECT year, country, SUM(CASE
WHEN bestlicence='Open Access' THEN 1
ELSE 0
END) AS OpenAccess, SUM(CASE
WHEN bestlicence<>'Open Access' THEN 1
ELSE 0
END) AS NonOpenAccess
FROM SOURCE.otherresearchproduct orp
join SOURCE.result_organization ro on orp.id=ro.id
join SOURCE.organization o on o.id=ro.organization
where cast(year as int)>=2003 and cast(year as int)<=2021
group by year, country) tmp
create table TARGET.indi_pub_avg_year_context_oa stored as parquet as
with total as
(select count(distinct pc.id) no_of_pubs, year, c.name name, sum(count(distinct pc.id)) over(PARTITION by year) as total from SOURCE.publication_concepts pc
join SOURCE.context c on pc.concept like concat('%',c.id,'%')
join SOURCE.publication p on p.id=pc.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by c.name, year )
select year, round(no_of_pubs/total*100,3) percentageofpubs, name
from total
create table TARGET.indi_dataset_avg_year_context_oa stored as parquet as
with total as
(select count(distinct pc.id) no_of_pubs, year, c.name name, sum(count(distinct pc.id)) over(PARTITION by year) as total from SOURCE.dataset_concepts pc
join SOURCE.context c on pc.concept like concat('%',c.id,'%')
join SOURCE.dataset p on p.id=pc.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by c.name, year )
select year, round(no_of_pubs/total*100,3) percentageofdataset, name
from total
create table TARGET.indi_software_avg_year_context_oa stored as parquet as
with total as
(select count(distinct pc.id) no_of_pubs, year, c.name name, sum(count(distinct pc.id)) over(PARTITION by year) as total from SOURCE.software_concepts pc
join SOURCE.context c on pc.concept like concat('%',c.id,'%')
join SOURCE.software p on p.id=pc.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by c.name, year )
select year, round(no_of_pubs/total*100,3) percentageofsoftware, name
from total
create table TARGET.indi_other_avg_year_context_oa stored as parquet as
with total as
(select count(distinct pc.id) no_of_pubs, year, c.name name, sum(count(distinct pc.id)) over(PARTITION by year) as total from SOURCE.otherresearchproduct_concepts pc
join SOURCE.context c on pc.concept like concat('%',c.id,'%')
join SOURCE.otherresearchproduct p on p.id=pc.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by c.name, year )
select year, round(no_of_pubs/total*100,3) percentageofother, name
from total
create table TARGET.indi_other_avg_year_content_oa stored as parquet as
with total as
(select count(distinct pd.id) no_of_pubs, year, d.type type, sum(count(distinct pd.id)) over(PARTITION by year) as total
from SOURCE.otherresearchproduct_datasources pd
join SOURCE.datasource d on datasource=d.id
join SOURCE.otherresearchproduct p on p.id=pd.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by d.type, year)
select year, round(no_of_pubs/total*100,3) percentageOfOtherresearchproduct, type
from total
create table TARGET.indi_software_avg_year_content_oa stored as parquet as
with total as
(select count(distinct pd.id) no_of_pubs, year, d.type type, sum(count(distinct pd.id)) over(PARTITION by year) as total
from SOURCE.software_datasources pd
join SOURCE.datasource d on datasource=d.id
join SOURCE.software p on p.id=pd.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by d.type, year)
select year, round(no_of_pubs/total*100,3) percentageOfSoftware, type
from total
create table TARGET.indi_dataset_avg_year_content_oa stored as parquet as
with total as
(select count(distinct pd.id) no_of_pubs, year, d.type type, sum(count(distinct pd.id)) over(PARTITION by year) as total
from SOURCE.dataset_datasources pd
join SOURCE.datasource d on datasource=d.id
join SOURCE.dataset p on p.id=pd.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by d.type, year)
select year, round(no_of_pubs/total*100,3) percentageOfDatasets, type
from total
create table TARGET.indi_pub_avg_year_content_oa stored as parquet as
with total as
(select count(distinct pd.id) no_of_pubs, year, d.type type, sum(count(distinct pd.id)) over(PARTITION by year) as total
from SOURCE.publication_datasources pd
join SOURCE.datasource d on datasource=d.id
join SOURCE.publication p on p.id=pd.id
where cast(year as int)>=2003 and cast(year as int)<=2021
group by d.type, year)
select year, round(no_of_pubs/total*100,3) percentageOfPubs, type
from total
create table TARGET.indi_pub_has_cc_licence_tr stored as parquet as
select distinct p.id, (case when lic='' or lic is null then 0 else 1 end) as has_cc_license_tr
from SOURCE.publication p
left outer join (select p.id, license.type as lic from SOURCE.publication p
join SOURCE.publication_licenses as license on license.id = p.id
where lower(license.type) LIKE '%creativecommons.org%' OR lower(license.type) LIKE '%cc-%') tmp
on p.id= tmp.id
create table TARGET.indi_pub_has_cc_licence_url stored as parquet as
select distinct p.id, (case when lic_host='' or lic_host is null then 0 else 1 end) as has_cc_license_url
from SOURCE.publication p
left outer join (select p.id, lower(parse_url(license.type, "HOST")) as lic_host
from SOURCE.publication p
join SOURCE.publication_licenses as license on license.id = p.id
WHERE lower(parse_url(license.type, 'HOST')) = 'creativecommons.org') tmp
on p.id= tmp.id
create table TARGET.indi_pub_has_cc_licence_f stored as parquet as
select distinct p.id, (case when lic='' or lic is null then 0 else 1 end) as has_cc_license_f
from SOURCE.publication p
left outer join (select p.id, license.type as lic from SOURCE.publication p
join SOURCE.publication_licenses as license on license.id = p.id
where lower(license.type) LIKE '%creativecommons.org%' OR lower(license.type) LIKE '%cc-%') tmp
on p.id= tmp.id
create table TARGET.indi_pub_has_abstract stored as parquet as
select distinct publication.id, coalesce(abstract, 1) has_abstract
from SOURCE.publication
compute stats TARGET.indi_pub_avg_year_country_oa;
compute stats TARGET.indi_dataset_avg_year_country_oa;
compute stats TARGET.indi_software_avg_year_country_oa;
compute stats TARGET.indi_other_avg_year_country_oa;
compute stats TARGET.indi_pub_avg_year_context_oa;
compute stats TARGET.indi_dataset_avg_year_context_oa;
compute stats TARGET.indi_software_avg_year_context_oa;
compute stats TARGET.indi_other_avg_year_context_oa;
compute stats TARGET.indi_other_avg_year_content_oa;
compute stats TARGET.indi_software_avg_year_content_oa;
compute stats TARGET.indi_dataset_avg_year_content_oa;
compute stats TARGET.indi_pub_avg_year_content_oa;
compute stats TARGET.indi_pub_has_cc_licence_tr;
compute stats TARGET.indi_pub_has_cc_licence_url;
compute stats TARGET.indi_pub_has_cc_licence_f;
compute stats TARGET.indi_pub_has_abstract;