Analytic invocation · over
---
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["Analytic invocation · over 📌<br/>🟢11"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_window_data_points["an(DS over (order by Id data points between n preceding and n following))"]:::ok
v_window_default_ds["an(DS over (partition by Id order by Id))"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_partition_by["an(Me over (partition by Id))"]:::ok
v_partition_except["an(Me over (partition except Id))"]:::ok
v_partition_except_all["an(over (partition except all order by Id)) 📌"]:::ok
v_order_asc["an(over (partition by Id order by Me asc))"]:::ok
v_order_desc["an(over (partition by Id order by Me desc))"]:::ok
v_window_range["an(Me over (partition by Id order by Me range between n preceding and n following))"]:::ok
v_window_unbounded["an(Me over (... data points between unbounded preceding and unbounded following))"]:::ok
v_window_current["an(Me over (... data points between n preceding and current data point))"]:::ok
v_window_default["an(Me over (partition by Id order by Id))"]:::ok
end
subgraph G_use["Used with"]
direction LR
used__clause__calc["calc ↗<br/><small>used in</small>"]:::ext
end
O --- G_ds
O --- G_comp
O -.- G_use
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_use fill:#ffffff,stroke:#868e96,stroke-width:1px,stroke-dasharray: 1 4
click v_partition_by href "#form-partition-by"
click v_partition_except href "#form-partition-except"
click v_partition_except_all href "#form-partition-except-all"
click v_order_asc href "#form-order-asc"
click v_order_desc href "#form-order-desc"
click v_window_data_points href "#form-window-data-points"
click v_window_range href "#form-window-range"
click v_window_unbounded href "#form-window-unbounded"
click v_window_current href "#form-window-current"
click v_window_default href "#form-window-default"
click v_window_default_ds href "#form-window-default-ds"
click used__clause__calc href "../clause/calc.html" "Calculation of a Component · calc"
Types
Takes any scalar · Gives any type
Comes from: any operator that returns a value
Goes to: whatever takes its input's type
Forms
an(DS over (order by Id data points between n preceding and n following)) 🟢 · any scalar → any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
sumat data set level over a window from one data point before to one after, with no partition clause.- Manual:
Analytic invocation, Example 1, with the manual’s data points: with no partition clause “the Data Set is partitioned by the Identifier Components that are not specified in the orderClause”, and the order names all three, so the data set is one partition.
- Expected:
in the order of the identifiers, -3 + 5 = 2, -3 + 5 + 13 = 15, and so on to 3 - 2 = 1.
Me_1may be Integer or Number: the manual prints Number, and the Sum page says “implementations may preserve the integer type” when all operand values are integer.
DS_r := sum ( DS_1 over ( order by Id_1, Id_2, Id_3 data points between 1 preceding and 1 following ) );
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| 2010 | E | XX | 5 |
| 2010 | B | XX | -3 |
| 2010 | R | XX | 9 |
| 2010 | E | YY | 13 |
| 2011 | E | XX | 11 |
| 2011 | B | ZZ | 7 |
| 2011 | E | YY | -1 |
| 2011 | F | XX | 0 |
| 2012 | L | ZZ | -2 |
| 2012 | E | YY | 3 |
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| 2010 | B | XX | 2 |
| 2010 | E | XX | 15 |
| 2010 | E | YY | 27 |
| 2010 | R | XX | 29 |
| 2011 | B | ZZ | 27 |
| 2011 | E | XX | 17 |
| 2011 | E | YY | 10 |
| 2011 | F | XX | 2 |
| 2012 | E | YY | 1 |
| 2012 | L | ZZ | 1 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(DS over (partition by Id order by Id)) 🟢 · any scalar → any type
Running total in time order 🟢 pandas ✅ · DuckDB ✅
- Tests:
sumat data set level, partitioned byId_1and ordered byId_2, with no window clause.- Manual:
Analytic invocation: “If the whole windowClause is omitted, then the default is either range between unbounded preceding and current data point or data points between unbounded preceding and unbounded following, depending respectively on whether orderClause clause was specified or not”. sdmx-twg/vtl#694 made it the default window of SQL. The Behaviour section of the page still says that the window is the whole partition, the rule of VTL 2.1.
- Expected:
in
A,Me_1is 3, 4, 9 and 10, andMe_21.5, 5, 7.5 and 8; inB,Me_1is 4 and 12, andMe_26.5 and 11.
DS_r := sum ( DS_1 over ( partition by Id_1 order by Id_2 ) );
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.5 |
| A | 2020Q2 | 4 | 5 |
| A | 2021Q1 | 9 | 7.5 |
| A | 2021Q2 | 10 | 8 |
| B | 2020Q1 | 4 | 6.5 |
| B | 2020Q2 | 12 | 11 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Ties count together 🟢 pandas ✅ · DuckDB ✅
- Tests:
sumat data set level, partitioned byId_1and ordered byId_2, with no window clause, where(A, 1, x)and(A, 1, y)tie onId_2.- Manual:
Analytic invocation: with an order clause and no window clause, the default is “range between unbounded preceding and current data point”. sdmx-twg/vtl#694 made it the default window of SQL, whose range takes in the data points that tie with the current one on the order keys.
- Expected:
in
A,Me_1is 1 + 2 = 3 on both tied data points, then 6 and 10; inB, 5 and 11.
DS_r := sum ( DS_1 over ( partition by Id_1 order by Id_2 ) );
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| A | 1 | x | 1 |
| A | 1 | y | 2 |
| A | 2 | x | 3 |
| A | 3 | x | 4 |
| B | 1 | x | 5 |
| B | 2 | x | 6 |
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| A | 1 | x | 3 |
| A | 1 | y | 3 |
| A | 2 | x | 6 |
| A | 3 | x | 10 |
| B | 1 | x | 5 |
| B | 2 | x | 11 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(Me over (partition by Id)) 🟢 · any scalar → any type
Sum per quarter 🟢 pandas ✅ · DuckDB ✅
- Tests:
partition by Id_2: thesumofMe_1incalcover the data points of the same quarter.- Manual:
Analytic invocation: “The input Data Set is partitioned according to the values of one or more Identifier Components”; with no window clause, the window is the whole partition.
- Expected:
Me_3= 3 + 4 = 7 for 2020Q1, 1 + 8 = 9 for 2020Q2, 5 for 2021Q1 and 1 for 2021Q2.
DS_r := DS_1 [ calc Me_3 := sum ( Me_1 over ( partition by Id_2 ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 7 |
| A | 2020Q2 | 1 | 3.500000 | 9 |
| A | 2021Q1 | 5 | 2.500000 | 5 |
| A | 2021Q2 | 1 | 0.500000 | 1 |
| B | 2020Q1 | 4 | 6.500000 | 7 |
| B | 2020Q2 | 8 | 4.500000 | 9 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(Me over (partition except Id)) 🟢 · any scalar → any type
Partition by unlisted identifier 🟢 pandas ✅ · DuckDB ✅
- Tests:
partition except Id_2: the data points are partitioned by the identifier that it does not list,Id_1.- Manual:
Analytic invocation, with the syntax
partition except identifier { , identifier }*: the partition is by the identifiers that are not listed.- Expected:
Me_3= 3 + 1 + 5 + 1 = 10 on the data points ofAand 4 + 8 = 12 on those ofB.
DS_r := DS_1 [ calc Me_3 := sum ( Me_1 over ( partition except Id_2 ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 10 |
| A | 2020Q2 | 1 | 3.500000 | 10 |
| A | 2021Q1 | 5 | 2.500000 | 10 |
| A | 2021Q2 | 1 | 0.500000 | 10 |
| B | 2020Q1 | 4 | 6.500000 | 12 |
| B | 2020Q2 | 8 | 4.500000 | 12 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(over (partition except all order by Id)) 🟢 · any scalar → any type
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
rankwithpartition except all, ordered byid_1, which the input namesId_1.- Manual:
Analytic invocation, Example 2:
partition except allleaves no identifier to partition by, and the User Manual makes regular names “case insensitive”, soid_1isId_1.- Expected:
the error
1-1-1-10, “Component {comp_name} not found in Dataset {dataset_name}.”: vtlengine keeps regular names case sensitive, soid_1is notId_1.- Team decision:
#633: regular names stay case sensitive until vtlengine 2.0, to avoid backward compatibility issues, although the User Manual makes them case insensitive.
DS_r:=DS_1[calc Me_2 := rank(over(partition except all order by id_1))];
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| 2010 | E | XX | 5 |
| 2010 | B | XX | -3 |
| 2010 | R | XX | 9 |
| 2010 | E | YY | 13 |
| 2011 | E | XX | 11 |
| 2011 | B | ZZ | 7 |
| 2011 | E | YY | -1 |
| 2011 | F | XX | 0 |
| 2012 | L | ZZ | -2 |
| 2012 | E | YY | 3 |
Expected error 1-1-1-10: Component {comp_name} not found in Dataset {dataset_name}.
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · example page ↗
Whole data set one partition 🟢 pandas ✅ · DuckDB ✅
- Tests:
partition except allwith the names written as declared (Manual example 2 writesid_1):rankover the whole data set, ordered byId_2.- Manual:
Analytic invocation:
partition except allleaves no identifier to partition by, so the data set is one partition (the rule for an omitted partition clause does not apply). On ties, Rank says “the same order number (rank) is assigned and a gap appears in the sequence of the assigned ranks”.- Expected:
2020Q1 (
AandB) ranks 1, 2020Q2 (AandB) ranks 3, 2021Q1 ranks 5 and 2021Q2 ranks 6.
DS_r := DS_1 [ calc Me_3 := rank ( over ( partition except all order by Id_2 ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 1 |
| A | 2020Q2 | 1 | 3.500000 | 3 |
| A | 2021Q1 | 5 | 2.500000 | 5 |
| A | 2021Q2 | 1 | 0.500000 | 6 |
| B | 2020Q1 | 4 | 6.500000 | 1 |
| B | 2020Q2 | 8 | 4.500000 | 3 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(over (partition by Id order by Me asc)) 🟢 · any scalar → any type
Ascending rank with tie 🟢 pandas ✅ · DuckDB ✅
- Tests:
order by Me_1 asc, with a tie:rankincalc, partitioned byId_1.- Manual:
Analytic invocation: “in ascending order if asc is specified”; Rank: “the same order number (rank) is assigned and a gap appears in the sequence of the assigned ranks”.
- Expected:
in
Athe two 1s rank 1, 3 ranks 3 and 5 ranks 4; inB4 ranks 1 and 8 ranks 2.
DS_r := DS_1 [ calc Me_3 := rank ( over ( partition by Id_1 order by Me_1 asc ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 3 |
| A | 2020Q2 | 1 | 3.500000 | 1 |
| A | 2021Q1 | 5 | 2.500000 | 4 |
| A | 2021Q2 | 1 | 0.500000 | 1 |
| B | 2020Q1 | 4 | 6.500000 | 1 |
| B | 2020Q2 | 8 | 4.500000 | 2 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(over (partition by Id order by Me desc)) 🟢 · any scalar → any type
Descending rank with tie 🟢 pandas ✅ · DuckDB ✅
- Tests:
order by Me_1 desc, with a tie:rankincalc, partitioned byId_1.- Manual:
Analytic invocation: “in descending order if desc is specified”; Rank: “the same order number (rank) is assigned and a gap appears in the sequence of the assigned ranks”.
- Expected:
in
A5 ranks 1, 3 ranks 2 and the two 1s rank 3; inB8 ranks 1 and 4 ranks 2.
DS_r := DS_1 [ calc Me_3 := rank ( over ( partition by Id_1 order by Me_1 desc ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 2 |
| A | 2020Q2 | 1 | 3.500000 | 3 |
| A | 2021Q1 | 5 | 2.500000 | 1 |
| A | 2021Q2 | 1 | 0.500000 | 3 |
| B | 2020Q1 | 4 | 6.500000 | 2 |
| B | 2020Q2 | 8 | 4.500000 | 1 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(Me over (partition by Id order by Me range between n preceding and n following)) 🟢 · any scalar → any type
Range bounds are inclusive 🟢 pandas ✅ · DuckDB ✅
- Tests:
a
rangewindow of 2 on each side, where values exactly 2 away are inside it.- Manual:
Analytic invocation: the window “includes all the Data Points whose values are in a certain range in respect to the value, for the current Data Point, of the Measure which the analytic is applied to”, and num gives “the maximum difference to consider”. The analytic is applied to
Me_1and ordered by it, so SQL’s range on the order key gives the same window.- Expected:
in
A(3, 1, 5, 1),Me_3is 10 for 3 (window [1, 5]), 5 for each 1 (window [-1, 3]) and 8 for 5 (window [3, 7]); inB, 4 and 8 are alone in their windows.
DS_r := DS_1 [ calc Me_3 := sum ( Me_1 over ( partition by Id_1 order by Me_1 range between 2 preceding and 2 following ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 10 |
| A | 2020Q2 | 1 | 3.500000 | 5 |
| A | 2021Q1 | 5 | 2.500000 | 8 |
| A | 2021Q2 | 1 | 0.500000 | 5 |
| B | 2020Q1 | 4 | 6.500000 | 4 |
| B | 2020Q2 | 8 | 4.500000 | 8 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(Me over (... data points between unbounded preceding and unbounded following)) 🟢 · any scalar → any type
Unbounded covers whole partition 🟢 pandas ✅ · DuckDB ✅
- Tests:
data points between unbounded preceding and unbounded following, with an order clause.- Manual:
Analytic invocation: “unbounded preceding means that the sliding window starts at the first Data Point of the partition” and “unbounded following indicates that the sliding window ends at the last Data Point of the partition”. With an order clause, an omitted window would be “range between unbounded preceding and current data point” instead.
- Expected:
Me_3is the sum of the whole partition on each data point: 10 inAand 12 inB.
DS_r := DS_1 [ calc Me_3 := sum ( Me_1 over ( partition by Id_1 order by Id_2 data points between unbounded preceding and unbounded following ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 10 |
| A | 2020Q2 | 1 | 3.500000 | 10 |
| A | 2021Q1 | 5 | 2.500000 | 10 |
| A | 2021Q2 | 1 | 0.500000 | 10 |
| B | 2020Q1 | 4 | 6.500000 | 12 |
| B | 2020Q2 | 8 | 4.500000 | 12 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(Me over (... data points between n preceding and current data point)) 🟢 · any scalar → any type
One preceding to current 🟢 pandas ✅ · DuckDB ✅
- Tests:
data points between 1 preceding and current data point, in the order ofId_2.- Manual:
Analytic invocation: “current data point specifies that the window starts or ends at the current Data Point”; with data points, 1 preceding is the data point before it.
- Expected:
in
A(3, 1, 5, 1),Me_3is 3, 3 + 1 = 4, 1 + 5 = 6 and 5 + 1 = 6; inB(4, 8), 4 and 4 + 8 = 12.
DS_r := DS_1 [ calc Me_3 := sum ( Me_1 over ( partition by Id_1 order by Id_2 data points between 1 preceding and current data point ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 3 |
| A | 2020Q2 | 1 | 3.500000 | 4 |
| A | 2021Q1 | 5 | 2.500000 | 6 |
| A | 2021Q2 | 1 | 0.500000 | 6 |
| B | 2020Q1 | 4 | 6.500000 | 4 |
| B | 2020Q2 | 8 | 4.500000 | 12 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
an(Me over (partition by Id order by Id)) 🟢 · any scalar → any type
Running total in time order 🟢 pandas ✅ · DuckDB ✅
- Tests:
sumincalc, partitioned byId_1and ordered byId_2, with no window clause.- Manual:
Analytic invocation: “If the whole windowClause is omitted, then the default is either range between unbounded preceding and current data point or data points between unbounded preceding and unbounded following, depending respectively on whether orderClause clause was specified or not”. sdmx-twg/vtl#694 made it the default window of SQL. The Behaviour section of the page still says that the window is the whole partition, the rule of VTL 2.1.
- Expected:
in
A(3, 1, 5, 1),Me_3is 3, 3 + 1 = 4, 4 + 5 = 9 and 9 + 1 = 10; inB(4, 8), 4 and 12.
DS_r := DS_1 [ calc Me_3 := sum ( Me_1 over ( partition by Id_1 order by Id_2 ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 3 |
| A | 2020Q2 | 1 | 3.500000 | 4 |
| A | 2021Q1 | 5 | 2.500000 | 9 |
| A | 2021Q2 | 1 | 0.500000 | 10 |
| B | 2020Q1 | 4 | 6.500000 | 4 |
| B | 2020Q2 | 8 | 4.500000 | 12 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Ties count together 🟢 pandas ✅ · DuckDB ✅
- Tests:
sumincalc, partitioned byId_1and ordered byId_2, with no window clause, where(A, 1, x)and(A, 1, y)tie onId_2.- Manual:
Analytic invocation: with an order clause and no window clause, the default is “range between unbounded preceding and current data point”. sdmx-twg/vtl#694 made it the default window of SQL, whose range takes in the data points that tie with the current one on the order keys.
- Expected:
in
A(1 and 2 atId_2= 1, 3 at 2, 4 at 3),Me_2is 1 + 2 = 3 on both tied data points, then 6 and 10; inB(5, 6), 5 and 11.
DS_r := DS_1 [ calc Me_2 := sum ( Me_1 over ( partition by Id_1 order by Id_2 ) ) ];
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| A | 1 | x | 1 |
| A | 1 | y | 2 |
| A | 2 | x | 3 |
| A | 3 | x | 4 |
| B | 1 | x | 5 |
| B | 2 | x | 6 |
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| A | 1 | x | 1 | 3 |
| A | 1 | y | 2 | 3 |
| A | 2 | x | 3 | 6 |
| A | 3 | x | 4 | 10 |
| B | 1 | x | 5 | 5 |
| B | 2 | x | 6 | 11 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
String order key 🟢 pandas ✅ · DuckDB ✅
- Tests:
the default window when the order key is a String,
Id_3:xon three data points ofAandyon the fourth.- Manual:
Analytic invocation: range “cannot be used for components having the following Data Types: String, Duration and TimeInterval Point”, but the default “range between unbounded preceding and current data point” has no offset to compute on the values of the key. It is read as applying whatever the type of the key, as in SQL.
- Expected:
in
A, the three data points atx(1, 3 and 4) tie, soMe_2is 8 on each, and 8 + 2 = 10 aty; inB(5 and 6, both atx), 11 on both.
DS_r := DS_1 [ calc Me_2 := sum ( Me_1 over ( partition by Id_1 order by Id_3 ) ) ];
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| A | 1 | x | 1 |
| A | 1 | y | 2 |
| A | 2 | x | 3 |
| A | 3 | x | 4 |
| B | 1 | x | 5 |
| B | 2 | x | 6 |
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| A | 1 | x | 1 | 8 |
| A | 1 | y | 2 | 10 |
| A | 2 | x | 3 | 8 |
| A | 3 | x | 4 | 8 |
| B | 1 | x | 5 | 11 |
| B | 2 | x | 6 | 11 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗