create table if not exists cmip6_search_result
(
    id                         varchar(118) null,
    version                    varchar(8)   null,
    access                     varchar(53)  null,
    activity_drs               varchar(15)  null,
    activity_id                varchar(15)  null,
    cf_standard_name           varchar(53)  null,
    citation_url               varchar(147) null,
    data_node                  varchar(25)  null,
    data_specs_version         varchar(12)  null,
    dataset_id_template_       varchar(141) null,
    datetime_start             datetime     null,
    datetime_stop              datetime     null,
    directory_format_template_ varchar(162) null,
    experiment_id              varchar(14)  null,
    experiment_title           varchar(45)  null,
    frequency                  varchar(7)   null,
    further_info_url           varchar(103) null,
    geo_units                  varchar(17)  null,
    grid                       varchar(164) null,
    grid_label                 varchar(8)   null,
    index_node                 varchar(22)  null,
    instance_id                varchar(98)  null,
    institution_id             varchar(23)  null,
    latest                     tinyint      null,
    master_id                  varchar(88)  null,
    member_id                  varchar(15)  null,
    mip_era                    varchar(9)   null,
    model_cohort               varchar(14)  null,
    nominal_resolution         varchar(14)  null,
    north_degrees              float        null,
    number_of_aggregations     int          null,
    number_of_files            int          null,
    pid                        varchar(53)  null,
    product                    varchar(16)  null,
    project                    varchar(9)   null,
    realm                      varchar(10)  null,
    replica                    tinyint      null,
    size                       bigint       null,
    source_id                  varchar(21)  null,
    source_type                varchar(47)  null,
    south_degrees              float        null,
    sub_experiment_id          varchar(8)   null,
    table_id                   varchar(9)   null,
    title                      varchar(88)  null,
    type                       varchar(7)   null,
    url                        varchar(473) null,
    variable                   varchar(15)  null,
    variable_id                varchar(15)  null,
    variable_long_name         varchar(58)  null,
    variable_units             varchar(14)  null,
    variant_label              varchar(15)  null,
    xlink                      varchar(248) null,
    _version_                  bigint       null,
    retracted                  tinyint      null,
    _timestamp                 datetime     null,
    score                      float        null,
    east_degrees               float        null,
    geo                        varchar(102) null,
    height_bottom              float        null,
    height_top                 float        null,
    height_units               varchar(11)  null,
    west_degrees               float        null,
    branch_method              varchar(12)  null,
    creation_date              varchar(20)  null,
    short_description          varchar(42)  null,
    datetime_end               varchar(20)  null,
    metadata_format            varchar(7)   null
);

create table if not exists cmip6_xml_links
(
    name             varchar(100) null,
    id               varchar(200) null,
    urlpath          varchar(400) null,
    restrictaccess   varchar(8)   null,
    service_name     varchar(10)  null,
    file_id          varchar(200) null,
    file_version     varchar(1)   null,
    size             bigint       null,
    tracking_id      varchar(50)  null,
    mod_time         datetime     null,
    checksum         varchar(64)  null,
    checksum_type    varchar(10)  null,
    vocabulary       varchar(10)  null,
    vocabulary_name  varchar(50)  null,
    vocabulary_units varchar(10)  null,
    vocabulary_text  varchar(60)  null,
    instance_id      varchar(100) null,
    http_server_base varchar(20)  null
);

create definer = root@`%` view cmip6_full_url as
select `b`.`instance_id`                                                         AS `INS_ID`,
       `a`.`name`                                                                AS `FILE_NAME`,
       concat('http://', `b`.`data_node`, `a`.`http_server_base`, `a`.`urlpath`) AS `FULL_URL`,
       `a`.`size`                                                                AS `FILE_SIZE`
from (`jd_data`.`cmip6_xml_links` `a`
         join (select `jd_data`.`cmip6_search_result`.`instance_id` AS `instance_id`,
                      `jd_data`.`cmip6_search_result`.`data_node`   AS `data_node`
               from `jd_data`.`cmip6_search_result`
               where (`jd_data`.`cmip6_search_result`.`id` is not null)) `b`
              on ((`a`.`instance_id` = `b`.`instance_id`)));

