ZSaed2.3 follower and following Top Users followers
    Updated 2023-03-06
    -- forked from 1c5940ca-503f-4ee4-ad51-4fbacbfa2a58

    -- forked from 82a63486-4271-4702-a3cb-42405cb9a440

    with flat as (
    with reg as (
    select a.*, parse_json(REGEXP_REPLACE(NODE_DATA,'null','"unfollow"')) as data from
    near.social.fact_decoded_actions a
    INNER join near.core.fact_transactions b on a.tx_hash = b.tx_hash and b.TX_STATUS ='Success'
    where NODE ='graph'
    and NODE_DATA:follow is not null
    )
    select
    *
    from reg,
    table(
    FLATTEN( INPUT =>data:follow)
    )
    -- where NODE ='graph'
    -- and NODE_DATA:follow is not null
    )
    , follow as (
    select SIGNER_ID,key, max(BLOCK_TIMESTAMP) as date from flat
    where value !='unfollow'
    -- and SIGNER_ID= 'manzanal.near'
    group by SIGNER_ID,key
    )
    ,unfollow as
    (
    select SIGNER_ID,key, max(BLOCK_TIMESTAMP) as date from flat
    where value ='unfollow'
    -- and SIGNER_ID= 'manzanal.near'
    group by SIGNER_ID,key
    )
    ,abslot_unfollow as (
    Run a query to Download Data