/*
 Copyright 2020 Curtin University
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 Author: Keegan Smith
 */
/*
This script creates a temporary table full of the supplied DOIs. 
It then joins these DOIs on the Crossref Events table. Also filters for events ocurring between start and end date. 
This gives the same result as using a WHERE statement for each DOI.
*/
CREATE TEMPORARY TABLE doi_table (DOI STRING);

{% for doi in dois %}
INSERT INTO doi_table (DOI) VALUES ('{{ doi }}');
{% endfor %}

SELECT
    xref.*
FROM
    `{{ project_id }}.{{ dataset_id }}.{{ crossref_events_table_id }}` xref
    JOIN doi_table ON xref.DOI = doi_table.DOI
    WHERE xref.ocurred_at >= {{ start_date }} AND xref.ocurred_at <= {{ end_date }}