Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tburm committed Dec 12, 2024
1 parent 017f980 commit ddfe13e
Showing 1 changed file with 54 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,80 @@
materialized = 'table',
) }}

WITH prices AS (
with prices as (

SELECT
DISTINCT market_symbol,
select distinct
market_symbol,
DATE_TRUNC(
'hour',
ts
) AS ts,
LAST_VALUE(price) over (PARTITION BY DATE_TRUNC('hour', ts), market_symbol
ORDER BY
ts rows BETWEEN unbounded preceding
AND unbounded following) AS price
FROM
) as ts,
LAST_VALUE(price) over (
partition by DATE_TRUNC('hour', ts), market_symbol
order by
ts
rows between unbounded preceding
and unbounded following
) as price
from
{{ ref('fct_prices_base_mainnet') }}
),
dim AS (
SELECT

dim as (
select
m.market_symbol,
generate_series(DATE_TRUNC('hour', MIN(t.ts)), DATE_TRUNC('hour', MAX(t.ts)), '1 hour' :: INTERVAL) AS ts
FROM
GENERATE_SERIES(
DATE_TRUNC('hour', MIN(t.ts)),
DATE_TRUNC('hour', MAX(t.ts)),
'1 hour'::INTERVAL
) as ts
from
(
SELECT
ts
FROM
select ts
from
prices
) AS t
CROSS JOIN (
SELECT
DISTINCT market_symbol
FROM
prices
) AS m
GROUP BY
) as t
cross join (
select distinct market_symbol
from
prices
) as m
group by
m.market_symbol
),
ffill AS (
SELECT

ffill as (
select
dim.ts,
dim.market_symbol,
last(
LAST(
prices.price
) over (
PARTITION BY dim.market_symbol
ORDER BY
dim.ts rows BETWEEN unbounded preceding
AND CURRENT ROW
) AS price
FROM
partition by dim.market_symbol
order by
dim.ts
rows between unbounded preceding
and current row
) as price
from
dim
LEFT JOIN prices
ON dim.ts = prices.ts
AND dim.market_symbol = prices.market_symbol
left join prices
on
dim.ts = prices.ts
and dim.market_symbol = prices.market_symbol
),
hourly_prices AS (
SELECT

hourly_prices as (
select
ts,
market_symbol,
price
FROM
from
ffill
)
SELECT
*
FROM

select *
from
hourly_prices
WHERE
price IS NOT NULL
where
price is not null

0 comments on commit ddfe13e

Please sign in to comment.