Query editor
WITH gs AS(selectcast(date_column as date) as dayfrom(valuessequence(cast('2020-11-30' as date),cast(date_trunc('day', current_timestamp) as date), interval '1' day)) as t1(date_array)cross join unnest(date_array) as t2(date_column)),erc20_token AS(select * from tokens.erc20where blockchain = 'ethereum')select *from(select r.*,gs.day as gs_dayfrom(select'AAVE_V2' as version,concat('AAVE_V2_',symbol) as version_symbol,cast(factor as double) /10000 as reserve_factor,e.symbol,cast(date_trunc('day', evt_block_time) as date) as day-- ,row_number() OVER (PARTITION BY asset ORDER BY evt_block_time desc) AS latest_order,lead(cast(date_trunc('day', evt_block_time) as date), 1, DATE_TRUNC('day',now() + interval '1' day ))OVER (PARTITION BY asset ORDER BY evt_block_time asc) AS next_dayfrom aave_v2_ethereum.LendingPoolConfigurator_evt_ReserveFactorChanged rleft join erc20_token e on r.asset = e.contract_address) rinner join gs on r.day <= gs.day AND gs.day < r.next_daywhere symbol in ('USDT','USDC','DAI','FRAX') and gs.day >= date('2022-01-01')union allselect r.*,gs.day as gs_day from(select'AAVE_V3' as version,concat('AAVE_V3_',symbol) as version_symbol,cast( newReserveFactor as double) /10000 as reserve_factor,e.symbol,cast(date_trunc('day', evt_block_time) as date) as day-- ,row_number() OVER (PARTITION BY asset ORDER BY evt_block_time desc) AS latest_order,lead(cast(date_trunc('day', evt_block_time) as date), 1, DATE_TRUNC('day',now() + interval '1' day ))OVER (PARTITION BY asset ORDER BY evt_block_time asc) AS next_dayfrom aave_v3_ethereum.PoolConfigurator_evt_ReserveFactorChanged rleft join erc20_token e on r.asset = e.contract_address) rinner join gs on r.day <= gs.day AND gs.day < r.next_daywhere symbol in ('USDT','USDC','DAI','FRAX') and gs.day >= date('2022-01-01'))t