2020-06-15 18:57:40 +02:00
|
|
|
------------------------------------------------------
|
|
|
|
------------------------------------------------------
|
|
|
|
-- Additional relations
|
|
|
|
--
|
|
|
|
-- Sources related tables/views
|
|
|
|
------------------------------------------------------
|
|
|
|
------------------------------------------------------
|
|
|
|
CREATE TABLE IF NOT EXISTS ${stats_db_name}.publication_sources as
|
|
|
|
SELECT p.id, case when d.id is null then 'other' else p.datasource end as datasource
|
|
|
|
FROM (
|
|
|
|
SELECT substr(p.id, 4) as id, substr(datasource, 4) as datasource
|
|
|
|
from ${openaire_db_name}.publication p lateral view explode(p.collectedfrom.key) c as datasource) p
|
|
|
|
LEFT OUTER JOIN
|
|
|
|
(
|
|
|
|
SELECT substr(d.id, 4) id
|
|
|
|
from ${openaire_db_name}.datasource d
|
2022-02-03 11:37:10 +01:00
|
|
|
WHERE d.datainfo.deletedbyinference=false and d.datainfo.invisible = FALSE) d on p.datasource = d.id;
|
2020-06-15 18:57:40 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS ${stats_db_name}.dataset_sources as
|
|
|
|
SELECT p.id, case when d.id is null then 'other' else p.datasource end as datasource
|
|
|
|
FROM (
|
|
|
|
SELECT substr(p.id, 4) as id, substr(datasource, 4) as datasource
|
|
|
|
from ${openaire_db_name}.dataset p lateral view explode(p.collectedfrom.key) c as datasource) p
|
|
|
|
LEFT OUTER JOIN
|
|
|
|
(
|
|
|
|
SELECT substr(d.id, 4) id
|
|
|
|
from ${openaire_db_name}.datasource d
|
2022-02-03 11:37:10 +01:00
|
|
|
WHERE d.datainfo.deletedbyinference=false and d.datainfo.invisible = FALSE) d on p.datasource = d.id;
|
2020-06-15 18:57:40 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS ${stats_db_name}.software_sources as
|
|
|
|
SELECT p.id, case when d.id is null then 'other' else p.datasource end as datasource
|
|
|
|
FROM (
|
|
|
|
SELECT substr(p.id, 4) as id, substr(datasource, 4) as datasource
|
|
|
|
from ${openaire_db_name}.software p lateral view explode(p.collectedfrom.key) c as datasource) p
|
|
|
|
LEFT OUTER JOIN
|
|
|
|
(
|
|
|
|
SELECT substr(d.id, 4) id
|
|
|
|
from ${openaire_db_name}.datasource d
|
2022-02-03 11:37:10 +01:00
|
|
|
WHERE d.datainfo.deletedbyinference=false and d.datainfo.invisible = FALSE) d on p.datasource = d.id;
|
2020-06-15 18:57:40 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS ${stats_db_name}.otherresearchproduct_sources as
|
|
|
|
SELECT p.id, case when d.id is null then 'other' else p.datasource end as datasource
|
|
|
|
FROM (
|
|
|
|
SELECT substr(p.id, 4) as id, substr(datasource, 4) as datasource
|
|
|
|
from ${openaire_db_name}.otherresearchproduct p lateral view explode(p.collectedfrom.key) c as datasource) p
|
|
|
|
LEFT OUTER JOIN
|
|
|
|
(
|
|
|
|
SELECT substr(d.id, 4) id
|
|
|
|
from ${openaire_db_name}.datasource d
|
2022-02-03 11:37:10 +01:00
|
|
|
WHERE d.datainfo.deletedbyinference=false and d.datainfo.invisible = FALSE) d on p.datasource = d.id;
|
2020-06-15 18:57:40 +02:00
|
|
|
|
|
|
|
CREATE VIEW IF NOT EXISTS ${stats_db_name}.result_sources AS
|
|
|
|
SELECT * FROM ${stats_db_name}.publication_sources
|
|
|
|
UNION ALL
|
|
|
|
SELECT * FROM ${stats_db_name}.dataset_sources
|
|
|
|
UNION ALL
|
|
|
|
SELECT * FROM ${stats_db_name}.software_sources
|
|
|
|
UNION ALL
|
|
|
|
SELECT * FROM ${stats_db_name}.otherresearchproduct_sources;
|
2021-07-28 11:28:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
create table ${stats_db_name}.result_orcid as
|
|
|
|
select distinct res.id, regexp_replace(res.orcid, 'http://orcid.org/' ,'') as orcid
|
|
|
|
from (
|
|
|
|
SELECT substr(res.id, 4) as id, auth_pid.value as orcid
|
|
|
|
FROM ${openaire_db_name}.result res
|
|
|
|
LATERAL VIEW explode(author) a as auth
|
|
|
|
LATERAL VIEW explode(auth.pid) ap as auth_pid
|
|
|
|
LATERAL VIEW explode(auth.pid.qualifier.classid) apt as author_pid_type
|
2021-12-23 14:46:17 +01:00
|
|
|
WHERE res.datainfo.deletedbyinference = FALSE and res.datainfo.invisible = FALSE and author_pid_type = 'orcid') as res;
|
|
|
|
|
|
|
|
create table ${stats_db_name}.result_result stored as parquet as
|
|
|
|
select substr(rel.source, 4) as source, substr(rel.target, 4) as target, relclass, subreltype
|
|
|
|
from ${openaire_db_name}.relation rel
|
|
|
|
join ${openaire_db_name}.result r1 on rel.source=r1.id
|
|
|
|
join ${openaire_db_name}.result r2 on r2.id=rel.target
|
|
|
|
where reltype='resultResult'
|
|
|
|
and r1.resulttype.classname!=r2.resulttype.classname
|
2022-02-03 11:37:10 +01:00
|
|
|
and r1.datainfo.deletedbyinference=false and r1.datainfo.invisible = FALSE
|
|
|
|
and r2.datainfo.deletedbyinference=false and r2.datainfo.invisible = FALSE
|
2021-12-23 14:46:17 +01:00
|
|
|
and r1.resulttype.classname != 'other'
|
|
|
|
and r2.resulttype.classname != 'other'
|
2022-02-03 11:37:10 +01:00
|
|
|
and rel.datainfo.deletedbyinference=false and rel.datainfo.invisible = FALSE;
|