Exists in · exists_in

🟢 4 of 4 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc3 (9e1c81a6) · 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
        ---
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["Exists in · exists_in<br/>🟢4"]:::ok
    v_retain_default["exists_in(DS, DS)"]:::ok
    v_retain_true["exists_in(DS, DS, true)"]:::ok
    v_retain_false["exists_in(DS, DS, false)"]:::ok
    v_retain_all["exists_in(DS, DS, all)"]:::ok
    v_retain_default --- O
    v_retain_true --- O
    O --- v_retain_false
    O --- v_retain_all
    click v_retain_default href "#form-retain-default"
    click v_retain_true href "#form-retain-true"
    click v_retain_false href "#form-retain-false"
    click v_retain_all href "#form-retain-all"
    

Types

Takes any scalar · Gives boolean

Viral attributes: combined with the propagation rules → Viral propagation

Comes from: any operator that returns a value

Goes to · boolean — 27 operators in 8 blocks 🟢27
General purpose operators (1) 🟢1
Join operators (4) 🟢4
Boolean operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (2) 🟢2
Clause operators (2) 🟢2
Definitions (VTL-DL) (3) 🟢3
Goes to · operators that take any scalar — 37 operators in 8 blocks 🟢37
General purpose operators (6) 🟢6
Comparison operators (10) 🟢10
Set operators (4) 🟢4
Aggregate and Analytic operators (7) 🟢7
Data validation operators (1) 🟢1
Conditional operators (1) 🟢1
Clause operators (7) 🟢7
Definitions (VTL-DL) (1) 🟢1

Forms

exists_in(DS, DS) 🟢 · any scalar → boolean

Identifier found with null measure 🟢 pandas ✅ · DuckDB ✅
Tests:

exists_in(DS_1, DS_2) with retain omitted: id 1 is in DS_2 with a null measure, id 2 is not in it.

Manual:

Exists in: “If the retain parameter is omitted, the default is all.” The operator “checks if the combinations of values of these Identifiers which are in op1 also exist in op2”.

Expected:

bool_var is true, false and true for ids 1 to 3, all of them returned: id 1 is found although its measure in DS_2 is null, because only the identifiers are looked at.

script.vtl
DS_r := exists_in(DS_1, DS_2);
Input DS_1
Id_1Me_1
110
220
330
Input DS_2
Id_1Me_1
1
37
Expected DS_r
Id_1bool_var
1true
2false
3true

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 ↗

exists_in(DS, DS, true) 🟢 · any scalar → boolean

Manual example 2 🟢 pandas ✅ · DuckDB ✅
Tests:

exists_in (DS_1, DS_2, true): only the data points of DS_1 that are found in DS_2.

Manual:

Exists in, Example 2, output verbatim: “If retain is true then only the data points with bool_var = true are returned.”

Expected:

B, S, F and W, with bool_var true; G and M are left out, as DS_2 has them only with Id_4 = M.

script.vtl
DS_r := exists_in (DS_1, DS_2, true);
Input DS_1
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal11094850
2012GTotalTotal11123034
2012STotalTotal46818219
2012MTotalTotal417546
2012FTotalTotal5401267
2012WTotalTotal7954662
Input DS_2
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal0.023
2012GTotalM0.286
2012STotalTotal0.064
2012MTotalM0.043
2012FTotalTotal
2012WTotalTotal0.08
Expected DS_r
Id_1Id_2Id_3Id_4bool_var
2012BTotalTotaltrue
2012STotalTotaltrue
2012FTotalTotaltrue
2012WTotalTotaltrue

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 ↗

exists_in(DS, DS, false) 🟢 · any scalar → boolean

Manual example 3 🟢 pandas ✅ · DuckDB ✅
Tests:

exists_in (DS_1, DS_2, false): only the data points of DS_1 that are not found in DS_2.

Manual:

Exists in, Example 3, output verbatim: “If retain is false then only the Data Points with bool_var = false are returned.”

Expected:

G and M, with bool_var false, as DS_2 has them only with Id_4 = M; B, S, F and W are left out.

script.vtl
DS_r := exists_in (DS_1, DS_2, false);
Input DS_1
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal11094850
2012GTotalTotal11123034
2012STotalTotal46818219
2012MTotalTotal417546
2012FTotalTotal5401267
2012WTotalTotal7954662
Input DS_2
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal0.023
2012GTotalM0.286
2012STotalTotal0.064
2012MTotalM0.043
2012FTotalTotal
2012WTotalTotal0.08
Expected DS_r
Id_1Id_2Id_3Id_4bool_var
2012GTotalTotalfalse
2012MTotalTotalfalse

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 ↗

exists_in(DS, DS, all) 🟢 · any scalar → boolean

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

exists_in (DS_1, DS_2, all): every data point of DS_1 is returned, found in DS_2 or not.

Manual:

Exists in, Example 1, output verbatim: “If retain is all then both the Data Points having bool_var = true and bool_var = false are returned.”

Expected:

bool_var is true for B, S, F and W, and false for G and M, which DS_2 has only with Id_4 = M, where DS_1 has Total; all six data points are returned.

script.vtl
DS_r := exists_in (DS_1, DS_2, all);
Input DS_1
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal11094850
2012GTotalTotal11123034
2012STotalTotal46818219
2012MTotalTotal417546
2012FTotalTotal5401267
2012WTotalTotal7954662
Input DS_2
Id_1Id_2Id_3Id_4Me_1
2012BTotalTotal0.023
2012GTotalM0.286
2012STotalTotal0.064
2012MTotalM0.043
2012FTotalTotal
2012WTotalTotal0.08
Expected DS_r
Id_1Id_2Id_3Id_4bool_var
2012BTotalTotaltrue
2012GTotalTotalfalse
2012STotalTotaltrue
2012MTotalTotalfalse
2012FTotalTotaltrue
2012WTotalTotaltrue

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 ↗