Period indicator · period_indicator

🟢 4 of 4 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc2 (90ee9376) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart TB
    classDef ok fill:#d4edda,stroke:#28a745,color:#000
    classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
    classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
    classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
    classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
    classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
    classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
    O["Period indicator · period_indicator<br/>🟢4"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_ds["period_indicator(DS)"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp["filter period_indicator(comp)"]:::ok
        v_in_filter_no_operand["filter period_indicator()"]:::ok
    end
    subgraph G_sc["Scalar"]
        direction LR
        v_sc["period_indicator(sc)"]:::ok
    end
    O --- G_ds
    O --- G_comp
    O --- G_sc
    style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
    style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
    style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
    click v_ds href "#form-ds"
    click v_comp href "#form-comp"
    click v_sc href "#form-sc"
    click v_in_filter_no_operand href "#form-in-filter-no-operand"
    

Types

Takes time_period · Gives duration

Goes to · duration — 6 operators in 3 blocks 🟢6
General purpose operators (1) 🟢1
Time operators (4) 🟢4
Definitions (VTL-DL) (1) 🟢1
Goes to · operators that take any scalar — 49 operators in 9 blocks 🟢49
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9
Definitions (VTL-DL) (1) 🟢1

Forms

period_indicator(DS) 🟢 · time_period → duration

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

period_indicator(DS_1): the period indicator of the time_period identifier Id_3 of each data point, in the one measure duration_var.

Manual:

Period indicator, Example 1, output verbatim: “The operator returns a Data Set with the same Identifiers of op and one Measure of type duration named duration_var.”

Expected:

A for the year 2010 and Q for 2013Q1, which the manual’s output writes 2013-Q1, the same period; Me_1 is dropped.

script.vtl
DS_r := period_indicator ( DS_1 );
Input DS_1
Id_1Id_2Id_3Me_1
A1201010
A12013Q150
Expected DS_r
Id_1Id_2Id_3duration_var
A12010A
A12013-Q1Q

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

filter period_indicator(comp) 🟢 · time_period → duration

Manual example 2 🟢 pandas ✅ · DuckDB ✅
Tests:

period_indicator(Id_3) inside filter, compared with cast("A", duration): the annual data points are kept.

Manual:

Period indicator, Example 2, output verbatim: “The period indicator is the part of the time_period value which denotes the duration of the time period (e.g. day, week, month…).”

Expected:

2010 has the indicator A and 2013Q1 has Q, so the data point of 2010 is kept, with all its components.

script.vtl
DS_r := DS_1 [ filter period_indicator ( Id_3 ) = cast("A", duration) ];
Input DS_1
Id_1Id_2Id_3Me_1
A1201010
A12013Q150
Expected DS_r
Id_1Id_2Id_3Me_1
A1201010

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

filter period_indicator() 🟢 · time_period → duration

Keeps the quarterly data point 🟢 pandas ✅ · DuckDB ✅
Tests:

period_indicator() with its operand left out, inside filter, compared with cast("Q", duration) as in Manual example 2; the one time_period identifier, Id_2, has the indicators A (2010), Q (2010Q1) and M (2010M01).

Manual:

Period indicator: “if used in a clause the operand op can be omitted”, and then “the Data Set to which the clause is applied has exactly one Identifier of type time_period”, from whose value the operator “extracts the period indicator”.

Expected:

The one data point whose indicator is Q: A, 2010Q1, 20.

script.vtl
DS_r := DS_1[filter period_indicator() = cast("Q", duration)];
Input DS_1
Id_1Id_2Me_1
A201010
A2010Q120
B2010M0130
Expected DS_r
Id_1Id_2Me_1
A2010Q120

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

period_indicator(sc) 🟢 · time_period → duration

Quarterly period 🟢 pandas ✅ · DuckDB ✅
Tests:

period_indicator(SC_1) on a scalar time_period, SC_1 = 2010Q1, an input scalar, as VTL has no time_period literal.

Manual:

Period indicator: “period_indicator returns the period indicator of a time_period value. The period indicator is the part of the time_period value which denotes the duration of the time period (e.g. day, week, month…).”

Expected:

DS_r = Q, a Duration: the manual’s default conversion from string to time_period (Type conversion) reads 2010Q1 as the first quarter of 2010.

script.vtl
DS_r := period_indicator(SC_1);
Input scalars
SC_1
2010Q1
Expected scalars

Name

Type

Value

DS_r

Duration

"Q"

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗