id: eurostat-hicp-inflation-mart
namespace: company.macro
description: |
Load the Eurostat Harmonised Index of Consumer Prices and the official annual rate for the geos you list, derive month-over-month and year-over-year inflation in DuckDB, and fail the execution when the derived year-over-year rate disagrees with Eurostat. The public SDMX 2.1 API needs no key. A schedule runs on the 17th; a webhook can start the same tasks when a release calendar fires.
inputs:
- id: geos
type: STRING
defaults: "DE;FR;IT;ES;NL"
displayName: Eurostat geo codes
description: Uppercase SDMX geo codes, separated by semicolons. Country codes
(DE) and aggregates (EA, EU27_2020) are both valid. No spaces.
- id: coicop
type: STRING
defaults: CP00
displayName: COICOP code
description: Classification of individual consumption by purpose. CP00 is
all-items HICP. The code must exist in both prc_hicp_midx and
prc_hicp_manr.
- id: start_period
type: STRING
defaults: "2024-01"
displayName: First month (YYYY-MM)
description: First month to request. Keep at least 13 months before the newest
published month so the year-over-year lag is defined. The gate fails when
it is not.
- id: yoy_tolerance_pp
type: FLOAT
defaults: 0.1
min: 0
displayName: Year-over-year tolerance (percentage points)
description: Largest absolute gap allowed between the derived year-over-year
rate and Eurostat's published annual rate. Both are rounded to 0.1.
triggers:
- id: monthly_hicp_release
type: io.kestra.plugin.core.trigger.Schedule
cron: "15 6 17 * *"
timezone: Europe/Brussels
recoverMissedSchedules: NONE
description: |
Eurostat usually has the full monthly HICP on the dissemination API by the 17th. 06:15 Europe/Brussels. Missed runs are not replayed, so importing the flow does not backfill the previous 17th.
- id: release_webhook
type: io.kestra.plugin.core.trigger.Webhook
key: "{{ secret('EUROSTAT_HICP_WEBHOOK_KEY') }}"
description: |
POST from a release calendar when the month is published. The key is the EUROSTAT_HICP_WEBHOOK_KEY secret. Manual Execute and the schedule do not read it.
concurrency:
limit: 1
behavior: QUEUE
tasks:
- id: inputs_ok
type: io.kestra.plugin.core.flow.If
description: Refuse codes that could change the SDMX path or the SQL before any
request is sent.
condition: "{{ (inputs.geos |
regexMatch(regex='^[A-Z][A-Z0-9_]{1,15}(;[A-Z][A-Z0-9_]{1,15})*$')) and
(inputs.coicop | regexMatch(regex='^[A-Z][A-Z0-9]{1,15}$')) and
(inputs.start_period | regexMatch(regex='^[0-9]{4}-(0[1-9]|1[0-2])$')) }}"
then:
- id: previous_period
type: io.kestra.plugin.core.kv.Get
description: Latest month already accepted for this COICOP. Empty on the first pass.
key: "eurostat_hicp_latest_{{ inputs.coicop }}"
errorOnMissing: false
- id: pull_eurostat
type: io.kestra.plugin.core.flow.Parallel
description: The index and the official annual rate are different datasets.
Fetch them together.
tasks:
- id: fetch_index
type: io.kestra.plugin.core.http.Download
description: |
HICP index, 2015=100 (prc_hicp_midx, unit I15, all-items or the COICOP you set). The path key is required. Query-string geo filters on this API do not slice the file. The Accept header avoids a 406.
uri: "https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/prc_hicp_mi\
dx/M.I15.{{ inputs.coicop }}.{{ inputs.geos | replace({';': '+'})
}}?format=SDMX-CSV&startPeriod={{ inputs.start_period
}}&detail=dataonly"
headers:
Accept: "application/vnd.sdmx.data+csv;version=1.0.0"
User-Agent: kestra-eurostat-hicp-inflation-mart/1.0 (+https://kestra.io)
options:
timeout:
readIdleTimeout: PT2M
retry:
type: exponential
interval: PT15S
maxInterval: PT1M
maxAttempts: 3
- id: fetch_official_yoy
type: io.kestra.plugin.core.http.Download
description: |
Official HICP annual rate of change (prc_hicp_manr, unit RCH_A) for the same geos, COICOP, and start month. This is the figure the derived rate is checked against.
uri: "https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/prc_hicp_ma\
nr/M.RCH_A.{{ inputs.coicop }}.{{ inputs.geos | replace({';':
'+'}) }}?format=SDMX-CSV&startPeriod={{ inputs.start_period
}}&detail=dataonly"
headers:
Accept: "application/vnd.sdmx.data+csv;version=1.0.0"
User-Agent: kestra-eurostat-hicp-inflation-mart/1.0 (+https://kestra.io)
options:
timeout:
readIdleTimeout: PT2M
retry:
type: exponential
interval: PT15S
maxInterval: PT1M
maxAttempts: 3
- id: build_mart
type: io.kestra.plugin.jdbc.duckdb.Queries
description: |
Derive month-over-month and year-over-year percent changes from the index (12-month lag, rounded to 0.1) and join Eurostat's published annual rate on geo and month.
fetchType: FETCH_ONE
inputFiles:
hicp_index.csv: "{{ outputs.fetch_index.uri }}"
hicp_official_yoy.csv: "{{ outputs.fetch_official_yoy.uri }}"
outputFiles:
- hicp_index
- inflation_rates
- reconciliation
sql: |
CREATE TABLE requested AS
SELECT UNNEST(str_split('{{ inputs.geos }}', ';')) AS geo;
CREATE TABLE idx AS
SELECT
geo,
TIME_PERIOD AS period,
TRY_CAST(OBS_VALUE AS DOUBLE) AS index_2015,
"LAST UPDATE" AS source_updated,
unit,
coicop
FROM read_csv('hicp_index.csv', header = true, all_varchar = true);
CREATE TABLE official AS
SELECT
geo,
TIME_PERIOD AS period,
TRY_CAST(OBS_VALUE AS DOUBLE) AS official_yoy_pct,
unit,
coicop
FROM read_csv('hicp_official_yoy.csv', header = true, all_varchar = true);
CREATE TABLE rates AS
SELECT
geo,
period,
index_2015,
source_updated,
ROUND(100.0 * (index_2015 / NULLIF(LAG(index_2015, 1) OVER (PARTITION BY geo ORDER BY period), 0) - 1), 1) AS mom_pct,
ROUND(100.0 * (index_2015 / NULLIF(LAG(index_2015, 12) OVER (PARTITION BY geo ORDER BY period), 0) - 1), 1) AS yoy_pct
FROM idx;
CREATE TABLE mart AS
SELECT
r.geo,
r.period,
r.index_2015,
r.mom_pct,
r.yoy_pct,
o.official_yoy_pct,
CASE
WHEN r.yoy_pct IS NOT NULL AND o.official_yoy_pct IS NOT NULL
THEN ROUND(r.yoy_pct - o.official_yoy_pct, 1)
END AS yoy_gap_pp,
r.source_updated
FROM rates r
LEFT JOIN official o
ON r.geo = o.geo
AND r.period = o.period;
COPY (
SELECT geo, period, index_2015, source_updated, unit, coicop
FROM idx
ORDER BY geo, period
) TO '{{ outputFiles.hicp_index }}' (FORMAT PARQUET);
COPY (
SELECT geo, period, index_2015, mom_pct, yoy_pct, official_yoy_pct, yoy_gap_pp, source_updated
FROM mart
ORDER BY geo, period
) TO '{{ outputFiles.inflation_rates }}' (FORMAT PARQUET);
COPY (
SELECT geo, period, yoy_pct, official_yoy_pct, yoy_gap_pp
FROM mart
WHERE yoy_pct IS NOT NULL AND official_yoy_pct IS NOT NULL
ORDER BY ABS(yoy_gap_pp) DESC, geo, period
) TO '{{ outputFiles.reconciliation }}' (HEADER, DELIMITER ',');
WITH stats AS (
SELECT
(SELECT COUNT(*) FROM requested)::INTEGER AS requested_geos,
(SELECT COUNT(DISTINCT geo) FROM idx)::INTEGER AS index_geos,
(SELECT COUNT(*) FROM requested r WHERE NOT EXISTS (SELECT 1 FROM idx i WHERE i.geo = r.geo))::INTEGER AS missing_geos,
(SELECT COUNT(*) FROM idx)::INTEGER AS index_rows,
(SELECT COUNT(*) FROM idx WHERE index_2015 IS NULL)::INTEGER AS null_index_rows,
COALESCE((SELECT MIN(c)::INTEGER FROM (SELECT COUNT(*) AS c FROM idx GROUP BY geo)), 0) AS min_months,
COALESCE((SELECT COUNT(DISTINCT latest)::INTEGER FROM (SELECT MAX(period) AS latest FROM idx GROUP BY geo)), 0) AS distinct_latest_periods,
(SELECT MAX(period) FROM idx) AS latest_period,
(SELECT COUNT(*) FROM mart WHERE yoy_pct IS NOT NULL AND official_yoy_pct IS NOT NULL)::INTEGER AS reconciled_rows,
COALESCE((SELECT MAX(ABS(yoy_pct - official_yoy_pct)) FROM mart WHERE yoy_pct IS NOT NULL AND official_yoy_pct IS NOT NULL), 0)::DOUBLE AS max_abs_pp_gap,
(SELECT MAX(source_updated) FROM idx) AS source_updated,
COALESCE((SELECT string_agg(geo || '=' || CAST(yoy_pct AS VARCHAR), ', ' ORDER BY geo) FROM mart WHERE period = (SELECT MAX(period) FROM mart) AND yoy_pct IS NOT NULL), '') AS latest_yoy,
(SELECT COUNT(*) FROM idx WHERE unit <> 'I15' OR coicop <> '{{ inputs.coicop }}')::INTEGER AS unexpected_index_rows,
(SELECT COUNT(*) FROM official WHERE unit <> 'RCH_A' OR coicop <> '{{ inputs.coicop }}')::INTEGER AS unexpected_yoy_rows
)
SELECT
requested_geos,
index_geos,
missing_geos,
index_rows,
null_index_rows,
min_months,
distinct_latest_periods,
latest_period,
reconciled_rows,
max_abs_pp_gap,
source_updated,
latest_yoy,
unexpected_index_rows,
unexpected_yoy_rows,
CASE
WHEN requested_geos > 0
AND missing_geos = 0
AND index_geos = requested_geos
AND null_index_rows = 0
AND min_months >= 13
AND distinct_latest_periods = 1
AND reconciled_rows >= requested_geos
AND max_abs_pp_gap <= {{ inputs.yoy_tolerance_pp }}
AND unexpected_index_rows = 0
AND unexpected_yoy_rows = 0
THEN 'PASS'
ELSE 'FAIL'
END AS gate
FROM stats;
- id: quality_gate
type: io.kestra.plugin.core.flow.If
description: Accept the month only when the derived year-over-year rate matches
Eurostat's published annual rate inside tolerance.
condition: "{{ outputs.build_mart.outputs[0].row.gate == 'PASS' }}"
then:
- id: remember_latest_period
type: io.kestra.plugin.core.kv.Set
description: Store the latest accepted month so the next run can say whether a
new month arrived.
key: "eurostat_hicp_latest_{{ inputs.coicop }}"
value: "{{ outputs.build_mart.outputs[0].row.latest_period }}"
- id: log_pass
type: io.kestra.plugin.core.log.Log
message: "HICP mart passed. latest={{
outputs.build_mart.outputs[0].row.latest_period }} previous={{
outputs.previous_period.value ?? 'none' }} geos={{
outputs.build_mart.outputs[0].row.index_geos }} index_rows={{
outputs.build_mart.outputs[0].row.index_rows }} reconciled={{
outputs.build_mart.outputs[0].row.reconciled_rows }} max_gap_pp={{
outputs.build_mart.outputs[0].row.max_abs_pp_gap }} source={{
outputs.build_mart.outputs[0].row.source_updated }} latest_yoy={{
outputs.build_mart.outputs[0].row.latest_yoy }}"
else:
- id: fail_quality
type: io.kestra.plugin.core.execution.Fail
errorMessage: "HICP reconciliation failed. geos={{
outputs.build_mart.outputs[0].row.index_geos }}/{{
outputs.build_mart.outputs[0].row.requested_geos }} missing={{
outputs.build_mart.outputs[0].row.missing_geos }} latest={{
outputs.build_mart.outputs[0].row.latest_period }} nulls={{
outputs.build_mart.outputs[0].row.null_index_rows }} min_months={{
outputs.build_mart.outputs[0].row.min_months }} distinct_latest={{
outputs.build_mart.outputs[0].row.distinct_latest_periods }}
reconciled={{ outputs.build_mart.outputs[0].row.reconciled_rows }}
max_gap_pp={{ outputs.build_mart.outputs[0].row.max_abs_pp_gap }}
tolerance={{ inputs.yoy_tolerance_pp }} unexpected_index={{
outputs.build_mart.outputs[0].row.unexpected_index_rows }}
unexpected_yoy={{
outputs.build_mart.outputs[0].row.unexpected_yoy_rows }}"
else:
- id: fail_inputs
type: io.kestra.plugin.core.execution.Fail
errorMessage: "geos must be uppercase Eurostat codes separated by semicolons
(DE;FR or EU27_2020), coicop a code such as CP00, and start_period
YYYY-MM. Got geos={{ inputs.geos }} coicop={{ inputs.coicop }}
start_period={{ inputs.start_period }}."
outputs:
- id: summary
type: JSON
value: "{{ outputs.build_mart.outputs[0].row }}"
description: Quality row from the mart. gate is PASS or FAIL.
- id: hicp_index
type: FILE
value: "{{ outputs.build_mart.outputFiles.hicp_index }}"
description: Parquet of geo, month, HICP index (2015=100), unit, COICOP, and the
Eurostat update stamp.
- id: inflation_rates
type: FILE
value: "{{ outputs.build_mart.outputFiles.inflation_rates }}"
description: Parquet with the index, derived month-over-month and year-over-year
rates, the official annual rate, and the gap in percentage points.
- id: reconciliation
type: FILE
value: "{{ outputs.build_mart.outputFiles.reconciliation }}"
description: CSV of months where both the derived and official year-over-year
rates exist, sorted by absolute gap.