Last active
October 26, 2016 07:02
-
-
Save itochu0523/7d04a8d6d0b30f27ef5ac6c4732b2dc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- INSERT INTO id_mapping -- presto | |
| With ssuid_table as | |
| ( | |
| select | |
| td_global_id | |
| ,max(ssuid) as ssuid | |
| from tmp_id_mapping | |
| group by td_global_id | |
| ), | |
| cluid_table as | |
| ( | |
| select | |
| td_global_id | |
| ,max(cluid) as cluid | |
| from tmp_id_mapping | |
| group by td_global_id | |
| ), | |
| tmp_id_mapping as | |
| ( | |
| SELECT | |
| (CASE WHEN b.ssuid is NULL and b.referrer_ssuid is not NULL THEN b.referrer_ssuid ELSE b.ssuid END) as ssuid | |
| ,b.fp_id as fp_id | |
| ,b.cluid as cluid | |
| ,b.td_global_id as td_global_id | |
| ,b.referrer_ssuid as referrer_ssuid | |
| FROM | |
| ( | |
| SELECT | |
| a.ssuid as ssuid | |
| ,a.fp_id as fp_id | |
| ,a.cluid as cluid | |
| ,a.td_global_id as td_global_id | |
| ,a.referrer_ssuid as referrer_ssuid | |
| FROM | |
| ( | |
| SELECT | |
| ssuid | |
| ,fp_id | |
| ,cluid | |
| ,td_global_id | |
| -- ,replace(regexp_extract(url_extract_query(td_referrer),'ssuid=\d+'),'ssuid=','') as referrer_ssuid -- presto | |
| ,parse_url(td_referrer, 'QUERY', 'ssuid') as referrer_ssuid -- Hive | |
| ,count(1) | |
| FROM | |
| catalina_glico | |
| GROUP BY | |
| 1,2,3,4,5 | |
| ) as a | |
| ) as b | |
| ) | |
| INSERT INTO TABLE id_mapping -- Hive | |
| SELECT | |
| a.td_global_id | |
| ,a.cluid | |
| ,b.ssuid | |
| FROM | |
| cluid_table a | |
| JOIN | |
| ssuid_table b | |
| ON a.td_global_id= b.td_global_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment