WITH new_data AS (
  SELECT
    client_id,
    sample_id,
    ad_clicks,
  FROM
    `moz-fx-data-shared-prod`.firefox_ios_derived.attributable_clients_v1
  WHERE
    submission_date = @submission_date
    AND ad_clicks > 0
),
existing_data AS (
  SELECT
    client_id,
    sample_id,
    ad_click_history
  FROM
    `moz-fx-data-shared-prod`.firefox_ios_derived.client_adclicks_history_v1
)
SELECT
  client_id,
  sample_id,
  mozfun.map.set_key(ad_click_history, @submission_date, ad_clicks) AS ad_click_history
FROM
  existing_data
FULL OUTER JOIN
  new_data
  USING (sample_id, client_id)
