{# 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: Richard Hosking, James Diprose #}

SELECT 
  UPPER(TRIM(doi)) as doi,
  MAX( wos_title ) as wos_title,
  MAX( wos_abstract ) as wos_abstract,
  MAX( wos_source ) as wos_source,
  MAX( wos_conference_id ) as wos_conference_id,
  MAX( wos_conference ) as wos_conference,
  MAX( wos_sortdate ) as wos_sortdate,
  MAX( wos_fund_ack ) as wos_fund_ack,
  MAX( wos_keywords ) as wos_keywords,
  MAX( wos_doi ) as wos_doi,
  MAX( wos_issn ) as wos_issn,
  MAX( wos_eissn ) as wos_eissn,
  MAX( wos_isbn ) as wos_isbn,
  MAX( wos_eisbn ) as wos_eisbn,
  MAX( wos_art_no ) as wos_art_no,
  MAX( wos_meeting_abs ) as wos_meeting_abs,
  MAX( wos_xref_doi ) as wos_xref_doi,
  MAX( wos_id ) as wos_id,
  MAX( wos_parent_book_doi ) as wos_parent_book_doi,
  ARRAY_AGG(grid_id) as grids
FROM `{{ project_id }}.{{ dataset_id }}.wos`
WHERE wos IS NOT NULL AND DOI IS NOT NULL
GROUP BY
  UPPER(TRIM(doi))