/* Reads from a cache that updates each 24 hours to remove computation
    and speed up filtering in dashboard */

    with historic_dau AS (
    select
    livequery.live.udf_api (
    'https://flipsidecrypto.xyz/api/v1/queries/598f021e-f026-4c9d-bc65-5be2a9972e11/data/latest'
    ):data as json_data
    ),

    dau_data AS (
    SELECT
    d.value:"CHAIN" AS chain,
    d.value:"DAY_" AS day_,
    -- d.value:"N_FACT_TX" AS N_FACT_TX,
    -- d.value:"MEDIAN_NONCE" AS MEDIAN_NONCE,
    d.value:"N_FIRST_TX" AS N_FIRST_TX,
    d.value:"N_UNIQUE_FROM" AS N_UNIQUE_FROM
    -- d.value:"N_UNIQUE_TO" AS N_UNIQUE_TO
    FROM
    historic_dau,
    LATERAL FLATTEN(input => historic_dau.json_data) d
    )

    select * from dau_data
    where day_ >= '{{min_date_daily}}'
    and day_ <= '{{max_date_daily}}'

    /*
    -- THIS QUERY IS INSTEAD CACHED SEPARATELY
    -- DASHBOARD FILTERS THE CACHE UP TO YESTERDAY
    -- SEE: https://flipsidecrypto.xyz/charliemarketplace/q/8CS2JtEudq8X/active_addresses_daily_through_yesterday_through_yesterday
    */


    Run a query to Download Data