Intersection · intersect
---
config:
flowchart:
useMaxWidth: false
---
flowchart LR
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["Intersection · intersect<br/>🟢2"]:::ok
v_two["intersect(DS, DS)"]:::ok
v_n["intersect(DS, DS, ...)"]:::ok
v_two --- O
O --- v_n
click v_two href "#form-two"
click v_n href "#form-n"
Types
Takes any scalar · Gives any type
Comes from: any operator that returns a value
Goes to: whatever takes its input's type
Forms
intersect(DS, DS) 🟢 · any scalar → any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
intersect(DS_1, DS_2): two data sets that share one data point, (2012, G, Total, Total), with the measure 2 in both.- Manual:
Intersection, Example 1, output verbatim: the resulting Data Set “contains the Data Points belonging to all the operand Data Sets”.
- Expected:
the page’s one data point, (2012, G, Total, Total) with the measure 2.
DS_r := intersect(DS_1, DS_2);
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | Total | 1 |
| 2012 | G | Total | Total | 2 |
| 2012 | F | Total | Total | 3 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2011 | B | Total | Total | 10 |
| 2012 | G | Total | Total | 2 |
| 2012 | M | Total | Total | 40 |
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | G | Total | Total | 2 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Leftmost wins when measures differ 🟢 pandas ✅ · DuckDB ✅
- Tests:
intersect(DS_1, DS_2)where ids 2 and 3 are in both operands with different measures (the page’s example shares one data point, with the same measure in both), to show whether data points are matched by identifiers alone and which one is kept. The measure is 10 *Id_1+ k, with k 0 forDS_1and 1 forDS_2, so its last digit names the operand.- Manual:
Intersection: duplicate Data Points “are filtered by choosing the Data Point belonging to the leftmost operand Data Set”; the User Manual: “The Data Points common (or not common) to the input Data Sets are determined by taking into account only the values of the Identifiers”.
- Expected:
Me_1is 20 and 30 for ids 2 and 3, the values ofDS_1, the leftmost operand; ids 1 and 4 are each in one operand only, so they are out.
DS_r := intersect(DS_1, DS_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| Id_1 | Me_1 |
|---|---|
| 2 | 21 |
| 3 | 31 |
| 4 | 41 |
| Id_1 | Me_1 |
|---|---|
| 2 | 20 |
| 3 | 30 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
intersect(DS, DS, ...) 🟢 · any scalar → any type
Point in all three operands 🟢 pandas ✅ · DuckDB ✅
- Tests:
intersect(DS_1, DS_2, DS_3), the list form with three operands, where the page’s example has two: ids 3 and 4 are in all three, and ids 1, 2 and 5 are each in two, lackingDS_2,DS_3andDS_1in turn. The measure is 10 *Id_1+ k, with k 0, 1 and 2 forDS_1,DS_2andDS_3.- Manual:
Intersection:
dsList ::= ds { , ds }*, the resulting Data Set “contains the Data Points belonging to all the operand Data Sets”, and duplicate Data Points “are filtered by choosing the Data Point belonging to the leftmost operand Data Set”.- Expected:
Me_1is 30 and 40 for ids 3 and 4, the values ofDS_1. Leaving outDS_1,DS_2orDS_3would add id 5, 1 or 2, so every operand takes part in the intersection.
DS_r := intersect(DS_1, DS_2, DS_3);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| Id_1 | Me_1 |
|---|---|
| 2 | 21 |
| 3 | 31 |
| 4 | 41 |
| 5 | 51 |
| Id_1 | Me_1 |
|---|---|
| 1 | 12 |
| 3 | 32 |
| 4 | 42 |
| 5 | 52 |
| Id_1 | Me_1 |
|---|---|
| 3 | 30 |
| 4 | 40 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · input/DS_3.csv · input/DS_3.json · expected/DS_r.csv · expected/DS_r.json · example page ↗