Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE PROCEDURE CANDIVORE.PROD.USER_BASE_STATS()
- RETURNS VARCHAR(16777216)
- LANGUAGE JAVASCRIPT
- EXECUTE AS CALLER
- AS '
- //2. Get the last day most updates user stats
- var my_sql_command2 = `
- INSERT INTO CANDIVORE.PROD.USER_DAILY_PARAMS
- select distinct
- derived_tstamp
- ,date(derived_tstamp) as interval_date
- ,session_id
- ,user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from (
- select *, RANK () OVER (PARTITION BY user_id, date(derived_tstamp) ORDER BY derived_tstamp DESC)
- as rank_row
- from(
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.video_watched
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.in_app_purchase
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.notification_opened
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.live_event_progression
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.client_restore_user
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.client_user_login
- where action != ''reconnected'' and date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- /*
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.user_loading
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL */
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.user_progression
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.core_user_resource_transaction
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,match_session_id as session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,client_IP
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,to_timestamp_ntz(first_install_DT) as first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.user_match
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- UNION ALL
- select distinct
- derived_tstamp
- ,session_id
- , user_id
- ,user_name
- ,country
- ,language
- ,device_language
- ,test_name
- ,test_group_name
- ,fb_user_ID
- ,USER_IPADDRESS
- ,is_testing_user
- ,is_developer
- ,team_ID
- ,device_ID
- ,device_model
- ,device_os
- ,platform
- ,media_source
- ,app_version
- ,app_minor_version
- ,first_install_DT
- ,advertiser_ID
- ,appsflyer_id
- ,ad_name
- ,campaign_name
- ,subscription_tier_id
- ,total_IAP_amt
- ,stars_cnt
- ,trophies_cnt
- ,LT_matches_played_cnt
- ,LT_matches_won_cnt
- ,LT_purchases_amt
- ,current_arena_index
- ,event_source
- ,ad_id
- ,adset
- ,adset_id
- ,campaign_id
- ,influencer_name
- ,af_keywords
- ,site_id
- ,team_name
- from snowplow.derived.user_session_start
- where date(derived_tstamp) = dateadd(day, -1,date(current_date()))
- )
- ) where rank_row = 1
- `
- var statement2 = snowflake.createStatement({sqlText: my_sql_command2});
- statement2.execute();
- var my_sql_command99 = "COMMIT;";
- var statement99 = snowflake.createStatement({sqlText: my_sql_command99});
- statement99.execute();
- ';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement