Spaces:
Running
Running
File size: 993 Bytes
2e6110c 22f4652 2e6110c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
with source as (
select * from {{ source('public', 'raw_ipc') }}
),
renamed as (
select
{{ adapter.quote("Clases") }} as class,
{{ adapter.quote("Tipo de dato") }} as type,
{{ adapter.quote("Periodo") }} as date,
{{ adapter.quote("Total") }} as value
from source
),
parsed as (
select
cast(strptime(REPLACE(date, 'M', '-'), '%Y-%m') as date) AS date,
class,
type,
try_cast(replace(value, ',', '.') AS FLOAT) AS value,
from renamed
),
cleaned as (
select
date,
case
when class != 'Índice general' then split_part(class, ' ', 1)
else '0000'
end as class_id,
case
when class != 'Índice general' then substring(class from position(' ' in class) + 1)
else 'Índice general'
end as class_name,
value
from parsed
where type = 'Índice'
order by date desc
)
select * from cleaned order by date desc
|