Element of · in

🟢 5 of 5 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["Element of · in<br/>🟢5"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_ds_set["DS in set"]:::ok
        v_ds_value_domain["DS in value domain"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp_set["comp in set"]:::ok
        v_comp_value_domain["comp in value domain"]:::ok
    end
    subgraph G_sc["Scalar"]
        direction LR
        v_sc_set["sc in set"]:::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_set href "#form-ds-set"
    click v_comp_set href "#form-comp-set"
    click v_sc_set href "#form-sc-set"
    click v_ds_value_domain href "#form-ds-value-domain"
    click v_comp_value_domain href "#form-comp-value-domain"
    

Types

Takes set, value domain, any scalar · Gives boolean

Comes from: any operator that returns a value

Comes from · set, value domain: none

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

DS in set 🟢 · any scalar, set → boolean

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

DS_1 in { 0, 3, 6, 12 }: every measure value of DS_1 against a set literal.

Manual:

Element of, Example 1, output verbatim: “The in operator returns true if op belongs to the collection, false otherwise.”

Expected:

bool_var is true for BS (0) and MO (6), and false for GZ, SQ, FJ and CQ (4, 9, 7 and 2).

script.vtl
DS_r := DS_1 in { 0, 3, 6, 12 };
Input DS_1
Id_1Id_2Me_1
2012BS0
2012GZ4
2012SQ9
2012MO6
2012FJ7
2012CQ2
Expected DS_r
Id_1Id_2bool_var
2012BStrue
2012GZfalse
2012SQfalse
2012MOtrue
2012FJfalse
2012CQfalse

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

DS in value domain 🟢 · any scalar, value domain → boolean

Manual example 3 🟢 pandas ✅ · DuckDB ✅
Tests:

DS_1#Id_2 in myGeoValueDomain: the identifier Id_2, taken as a measure by the membership operator, against a value domain.

Manual:

Element of, Example 3, output verbatim: “The in operator returns true if op belongs to the collection, false otherwise.” The page defines the Value Domain myGeoValueDomain (string) in the text before its examples, not in their files, as {"AF", "BS", "FJ", "GA", "KH", "MO", "PK", "QA", "UG"}; it is passed to run as value_domains/myGeoValueDomain.json.

Expected:

bool_var is true for BS, MO and FJ, which are elements of the value domain, and false for GZ, SQ and CQ, which are not.

script.vtl
DS_r := DS_1#Id_2 in myGeoValueDomain;
Input DS_1
Id_1Id_2Me_1
2012BS0
2012GZ4
2012SQ9
2012MO6
2012FJ7
2012CQ2
Expected DS_r
Id_1Id_2bool_var
2012BStrue
2012GZfalse
2012SQfalse
2012MOtrue
2012FJtrue
2012CQfalse

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

comp in set 🟢 · any scalar, set → boolean

Manual example 2 🟢 pandas ✅ · DuckDB ✅
Tests:

Me_1 in { 0, 3, 6, 12 } inside calc, where the new measure Me_2 takes the result.

Manual:

Element of, Example 2, output verbatim: “The in operator returns true if op belongs to the collection, false otherwise.”

Expected:

Me_2 is true for BS and MO, and false for GZ, SQ, FJ and CQ; Me_1 is kept.

script.vtl
DS_r := DS_1 [ calc Me_2:= Me_1 in { 0, 3, 6, 12 } ];
Input DS_1
Id_1Id_2Me_1
2012BS0
2012GZ4
2012SQ9
2012MO6
2012FJ7
2012CQ2
Expected DS_r
Id_1Id_2Me_1Me_2
2012BS0true
2012GZ4false
2012SQ9false
2012MO6true
2012FJ7false
2012CQ2false

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

comp in value domain 🟢 · any scalar, value domain → boolean

Members and null operand 🟢 pandas ✅ · DuckDB ✅
Tests:

Me_1 in myGeoValueDomain inside calc: the elements AF and UG (the first and the last of the value domain), the non-element CQ and a null.

Manual:

Element of: “The in operator returns true if op belongs to the collection, false otherwise.” The page defines the Value Domain myGeoValueDomain (string) in the text before its examples, as {"AF", "BS", "FJ", "GA", "KH", "MO", "PK", "QA", "UG"}; it is passed to run as value_domains/myGeoValueDomain.json.

Expected:

Me_2 is a new boolean measure: true for AF, false for CQ, true for UG and null for the null; Me_1 is kept. A null operand gives a null result: “Whenever a null value is involved in a comparison (>, <, >=, <=, in, not in, between) the result of the comparison is null” (User Manual).

script.vtl
DS_r := DS_1 [ calc Me_2 := Me_1 in myGeoValueDomain ];
Input DS_1
Id_1Me_1
1AF
2CQ
3UG
4
Expected DS_r
Id_1Me_1Me_2
1AFtrue
2CQfalse
3UGtrue
4

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

sc in set 🟢 · any scalar, set → boolean

Member of a set 🟢 pandas ✅ · DuckDB ✅
Tests:

SC_1 in { 1, 2, 3 } with SC_1 = 1: a scalar that is an element of a set literal.

Manual:

Element of, semantics for scalar operations: “1 in { 1, 2, 3 } returns true”.

Expected:

SC_r = true, a Boolean: 1 is an element of the set.

script.vtl
SC_r := SC_1 in { 1, 2, 3 };
Input scalars
SC_1
1
Expected scalars

Name

Type

Value

SC_r

Boolean

true

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