define operator

🟢 13 of 13 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 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["define operator 📌<br/>🟢13"]:::ok
    subgraph G_b1["Signature"]
        direction LR
        v_no_parameters["f ()"]:::ok
        v_scalar_type["x #60;scalar type#62;"]:::ok
        v_value_domain["x #60;value domain#62;"]:::ok
        v_constrained_scalar["x #60;scalar type#62; #91;value …#93; #124; #123; … #125; #124; not null"]:::ok
        v_set["s set#60;…#62;"]:::ok
        v_component["c component #124; identifier #124; measure #124; attribute #124; viral attribute #60;…#62; 📌"]:::ok
        v_dataset["ds dataset #91;#123; … #125;#93;"]:::ok
        v_ruleset["r #60;ruleset type#62;"]:::ok
        v_default_value["y #60;type#62; default …"]:::ok
    end
    subgraph G_b2["Return type"]
        direction LR
        v_returns_omitted["no returns"]:::ok
        v_returns_scalar["returns #60;scalar type#62;"]:::ok
        v_returns_component["returns component#60;…#62;"]:::ok
        v_returns_dataset["returns dataset"]:::ok
    end
    O --- G_b1
    O --- G_b2
    style G_b1 fill:#f8f9fa,stroke:#868e96,stroke-width:1px
    style G_b2 fill:#f8f9fa,stroke:#868e96,stroke-width:1px
    click v_no_parameters href "#form-no-parameters"
    click v_scalar_type href "#form-scalar-type"
    click v_value_domain href "#form-value-domain"
    click v_constrained_scalar href "#form-constrained-scalar"
    click v_set href "#form-set"
    click v_component href "#form-component"
    click v_dataset href "#form-dataset"
    click v_ruleset href "#form-ruleset"
    click v_default_value href "#form-default-value"
    click v_returns_omitted href "#form-returns-omitted"
    click v_returns_scalar href "#form-returns-scalar"
    click v_returns_component href "#form-returns-component"
    click v_returns_dataset href "#form-returns-dataset"
    

Types

Takes number, integer, string, boolean, time, date, time_period, duration, set, value domain, datapoint ruleset, hierarchical ruleset, any scalar · Gives operator

Comes from: any operator that returns a value

Comes from · set, value domain, datapoint ruleset, hierarchical ruleset — 2 operators in 1 block 🟢2
Definitions (VTL-DL) (2) 🟢2
Goes to · operator — 1 operator in 1 block 🟢1
General purpose operators (1) 🟢1

Forms

Signature

f () 🟢 · nothing → operator

Call without arguments 🟢 pandas ✅ · DuckDB ✅
Tests:

an operator with no parameters, called as answer().

Manual:

define operator: define operator operator_name ( { parameter { , parameter }* } ), with optional parameters, so the call operatorName ( { argument { , argument }* } ) passes none. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 42, an Integer: 6 * 7.

script.vtl
define operator answer ()
    returns integer is
        6 * 7
end operator;

SC_r := answer();
Expected scalars

Name

Type

Value

SC_r

Integer

42

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

x <scalar type> 🟢 · any scalar, number, integer, string, boolean, time, date, time_period, duration → operator

Integer argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type integer, called as add_one(SC_1) with SC_1 = 2.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... integer ...). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 3, an Integer: 2 + 1.

script.vtl
define operator add_one (x integer)
    returns integer is
        x + 1
end operator;

SC_r := add_one(SC_1);
Input scalars
SC_1
2
Expected scalars

Name

Type

Value

SC_r

Integer

3

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

Number argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type number, called as twice(SC_1) with SC_1 = 1.25.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... number ...). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 2.5, a Number: 1.25 * 2.

script.vtl
define operator twice (x number)
    returns number is
        x * 2
end operator;

SC_r := twice(SC_1);
Input scalars
SC_1
1.25
Expected scalars

Name

Type

Value

SC_r

Number

2.5

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

String argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type string, called as with_suffix(SC_1) with SC_1 = A.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... string ...). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = "A_B", a String: "A" || "_B".

script.vtl
define operator with_suffix (x string)
    returns string is
        x || "_B"
end operator;

SC_r := with_suffix(SC_1);
Input scalars
SC_1
A
Expected scalars

Name

Type

Value

SC_r

String

"A_B"

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

Boolean argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type boolean, called as negation(SC_1) with SC_1 = true.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... boolean ...). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = false, a Boolean: not true.

script.vtl
define operator negation (x boolean)
    returns boolean is
        not x
end operator;

SC_r := negation(SC_1);
Input scalars
SC_1
true
Expected scalars

Name

Type

Value

SC_r

Boolean

false

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

Date argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type date, called as same_date(SC_1) with the Date SC_1 = 2020-01-15: a date has no literal, so the argument is an input scalar.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... date ...), and the User Manual says that these types “do not directly support literals”: their values are “converted in the desired type by the cast operator”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 2020-01-15, a Date: the body returns its argument.

script.vtl
define operator same_date (x date)
    returns date is
        x
end operator;

SC_r := same_date(SC_1);
Input scalars
SC_1
2020-01-15
Expected scalars

Name

Type

Value

SC_r

Date

"2020-01-15"

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

Time period argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type time_period, called as same_period(SC_1) with the Time_Period SC_1 = 2020Q1, the first quarter of 2020 in the manual’s representation.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... time_period ...), and the User Manual says that these types “do not directly support literals”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 2020Q1, a Time_Period: the body returns its argument.

script.vtl
define operator same_period (x time_period)
    returns time_period is
        x
end operator;

SC_r := same_period(SC_1);
Input scalars
SC_1
2020Q1
Expected scalars

Name

Type

Value

SC_r

Time_Period

"2020Q1"

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

Time argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type time, called as same_time(SC_1) with the Time SC_1 = 2020-01-01/2020-12-31, the year 2020 in the manual’s representation YYYY-MM-DD/YYYY-MM-DD.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... time ...), and the User Manual says that these types “do not directly support literals”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 2020-01-01/2020-12-31, a Time: the body returns its argument.

script.vtl
define operator same_time (x time)
    returns time is
        x
end operator;

SC_r := same_time(SC_1);
Input scalars
SC_1
2020-01-01/2020-12-31
Expected scalars

Name

Type

Value

SC_r

Time

"2020-01-01/2020-12-31"

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

Duration argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type duration, called as same_duration(SC_1) with the Duration SC_1 = M: M, a month, is one of the User Manual’s one-character codes of the duration type.

Manual:

define operator: a parameter type is “a VTL data type” (basicScalarType ::= ... duration ...), and the User Manual says that these types “do not directly support literals”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = M, a Duration: the body returns its argument.

script.vtl
define operator same_duration (x duration)
    returns duration is
        x
end operator;

SC_r := same_duration(SC_1);
Input scalars
SC_1
M
Expected scalars

Name

Type

Value

SC_r

Duration

"M"

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

Scalar argument keeps its type 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type scalar, with returns scalar, called as same_scalar(SC_1) with the Integer SC_1 = 5.

Manual:

define operator: basicScalarType ::= scalar | ..., and in the User Manual “The super-type of all the scalar types is the type scalar”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 5, an Integer: the body returns its argument, which keeps its type, as returns scalar allows any scalar type.

script.vtl
define operator same_scalar (x scalar)
    returns scalar is
        x
end operator;

SC_r := same_scalar(SC_1);
Input scalars
SC_1
5
Expected scalars

Name

Type

Value

SC_r

Integer

5

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

x <value domain> 🟢 · value domain → operator

String value of the domain 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter typed by the value domain VD_1, of the strings A, B and C, called as with_suffix(SC_1) with SC_1 = A.

Manual:

define operator: scalarType ::= { basicScalarType | valueDomainName | setName } ..., and in Type conversion a basic scalar value is “implicitly converted into a value belonging to a value domain” while “an element of a value domain is implicitly upcast into its corresponding basic scalar type”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = "A_X", a String: "A" is a value of VD_1, and x || "_X" concatenates it as a string.

script.vtl
define operator with_suffix (x VD_1)
    returns string is
        x || "_X"
end operator;

SC_r := with_suffix(SC_1);
Input scalars
SC_1
A
Expected scalars

Name

Type

Value

SC_r

String

"A_X"

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

x <scalar type> [value …] | { … } | not null 🟢 · integer → operator

Value condition holds 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter with a condition, x integer [value >= 0], called as times_ten(SC_1) with SC_1 = 2.

Manual:

define operator: scalarTypeConstraint ::= [ valueBooleanCondition ] | ..., a condition “expressed with reference to the fictitious variable” value, as in number [ value >= 0 ]. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 20, an Integer: 2 meets the condition, and 2 * 10 = 20.

script.vtl
define operator times_ten (x integer [value >= 0])
    returns integer is
        x * 10
end operator;

SC_r := times_ten(SC_1);
Input scalars
SC_1
2
Expected scalars

Name

Type

Value

SC_r

Integer

20

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

Value in the list 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter restricted to a list of values, x integer { 1, 2, 3 }, called as times_ten(SC_1) with SC_1 = 2.

Manual:

define operator: scalarTypeConstraint ::= ... | { scalarLiteral { , scalarLiteral }* }, as in “integer { 0, 1 } means an integer number whose value is 0 or 1”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 20, an Integer: 2 is in the list, and 2 * 10 = 20.

script.vtl
define operator times_ten (x integer { 1, 2, 3 })
    returns integer is
        x * 10
end operator;

SC_r := times_ten(SC_1);
Input scalars
SC_1
2
Expected scalars

Name

Type

Value

SC_r

Integer

20

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

Non null argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type integer not null, called as add_one(SC_1) with SC_1 = 2.

Manual:

define operator: scalarType ::= ... { { not } null }. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 3, an Integer: 2 is not null, and 2 + 1 = 3.

script.vtl
define operator add_one (x integer not null)
    returns integer is
        x + 1
end operator;

SC_r := add_one(SC_1);
Input scalars
SC_1
2
Expected scalars

Name

Type

Value

SC_r

Integer

3

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

s set<…> 🟢 · set → operator

Value domain as the set 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type set<string>, called as is_in(SC_1, VD_AB) with SC_1 = B and the value domain VD_AB (A and B) passed by its name, as the grammar takes set literals only after in and not_in.

Manual:

define operator: scalarSetType ::= set { < scalarType > }, and in Element of a set “can be a Set name or a Set literal” and the collection is “the Set or the Value Domain which contains the values”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = true, a Boolean: "B" in s holds, as B is a value of VD_AB.

script.vtl
define operator is_in (x string, s set<string>)
    returns boolean is
        x in s
end operator;

SC_r := is_in(SC_1, VD_AB);
Input scalars
SC_1
B
Expected scalars

Name

Type

Value

SC_r

Boolean

true

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

c component | identifier | measure | attribute | viral attribute <…> 🟢 · any scalar, integer, string → operator

Component role in calc 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type component, with no scalar type, called inside calc with the Measure Me_1.

Manual:

define operator: componentType ::= componentRole { < scalarType > }, and without <...> a component “can be of any scalar type” (User Manual). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_2 = Me_1 * 2, a new Measure that calc adds (“If the calculated Component is a new Component, it is added to the output Data Set”): (1, 10, 20) and (2, 20, 40).

script.vtl
define operator twice (c component)
    returns component is
        c * 2
end operator;

DS_r := DS_1[calc Me_2 := twice(Me_1)];
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1Me_2
11020
22040

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

Identifier in calc 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type identifier<integer>, called inside calc with the Identifier Id_1.

Manual:

define operator: componentRole ::= component | identifier | measure | attribute | viral attribute. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_2 = Id_1 * 10, a new Measure that calc adds: (1, 10, 10) and (2, 20, 20).

script.vtl
define operator times_ten (c identifier<integer>)
    returns component<integer> is
        c * 10
end operator;

DS_r := DS_1[calc Me_2 := times_ten(Id_1)];
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1Me_2
11010
22020

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

Measure role in calc 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type measure<integer>, called inside calc with the Measure Me_1.

Manual:

define operator: componentRole ::= component | identifier | measure | attribute | viral attribute. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_2 = Me_1 * 2, a new Measure that calc adds: (1, 10, 20) and (2, 20, 40).

script.vtl
define operator twice (c measure<integer>)
    returns component<integer> is
        c * 2
end operator;

DS_r := DS_1[calc Me_2 := twice(Me_1)];
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1Me_2
11020
22040

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

Attribute overwritten in calc 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type attribute<string>, whose result overwrites the Attribute At_1 in calc.

Manual:

define operator: componentRole ::= component | identifier | measure | attribute | viral attribute, and in calc “the calculated values overwrite the original values” of an existing Attribute, which with no role “maintains its role”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

At_1 stays an Attribute with A_X and B_X. Calculating it explicitly keeps the propagation rule out, as it “does not apply if the operations on the Attributes to be propagated are explicitly specified in the expression”.

script.vtl
define operator with_suffix (c attribute<string>)
    returns component<string> is
        c || "_X"
end operator;

DS_r := DS_1[calc At_1 := with_suffix(At_1)];
Input DS_1
Id_1Me_1At_1
110A
220B
Expected DS_r
Id_1Me_1At_1
110A_X
220B_X

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

Viral attribute overwritten in calc 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type viral attribute<string>, whose result overwrites the viral At_1 in calc.

Manual:

define operator: componentRole ::= component | identifier | measure | attribute | viral attribute, and in calc “the calculated values overwrite the original values” of an existing Attribute, which with no role “maintains its role”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

At_1 stays a Viral Attribute with A_X and B_X, as “a viral Attribute in the input generates a homonymous viral Attribute also in the result” (User Manual). No propagation rule is needed: one data point gives one, so “the values of the viral Attributes are simply copied”.

Team decision:

#1257: as the comments on sdmx-twg/vtl#731 propose, a viral Attribute needs a propagation rule only where its values are combined, until the VTL Task Force discusses it.

script.vtl
define operator with_suffix (c viral attribute<string>)
    returns component<string> is
        c || "_X"
end operator;

DS_r := DS_1[calc At_1 := with_suffix(At_1)];
Input DS_1
Id_1Me_1At_1
110A
220B
Expected DS_r
Id_1Me_1At_1
110A_X
220B_X

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

ds dataset [{ … }] 🟢 · any scalar → operator

Dataset argument 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type dataset, with no component constraint, called with DS_1.

Manual:

define operator: datasetType ::= dataset { ... }, here without constraints: the super-type of the Data Set types, “any dataset” (User Manual). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_1 * 2 on each data point, as “the operator is applied to the values of all the Measures”: (1, 20) and (2, 40).

script.vtl
define operator twice (ds dataset)
    returns dataset is
        ds * 2
end operator;

DS_r := twice(DS_1);
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1
120
240

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

Named components 🟢 pandas ✅ · DuckDB ✅
Tests:

a dataset parameter whose constraints name its components, dataset { identifier<integer> Id_1, measure<integer> Me_1 }: the structure of DS_1.

Manual:

define operator: componentConstraint ::= componentType { componentName | multiplicityModifier }. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_1 * 2 on each data point: (1, 20) and (2, 40).

script.vtl
define operator twice (ds dataset { identifier<integer> Id_1, measure<integer> Me_1 })
    returns dataset is
        ds * 2
end operator;

DS_r := twice(DS_1);
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1
120
240

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

Exactly one measure 🟢 pandas ✅ · DuckDB ✅
Tests:

the multiplicity modifier _ in place of a component name, dataset { measure<integer> _ }, which the one integer Measure of DS_1 meets.

Manual:

define operator: multiplicityModifier ::= _ { + | * }, and in the User Manual “The underscore _ indicates that the preceding type appears just one time”, the form of the manual’s own operands such as dataset { measure<number> _ }. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_1 * 2 on each data point: (1, 20) and (2, 40).

script.vtl
define operator twice (ds dataset { measure<integer> _ })
    returns dataset is
        ds * 2
end operator;

DS_r := twice(DS_1);
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1
120
240

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

One or more measures 🟢 pandas ✅ · DuckDB ✅
Tests:

the multiplicity modifier _+, dataset { measure<integer> _+ }, with the two integer Measures of DS_1.

Manual:

define operator: multiplicityModifier ::= _ { + | * }, and in the User Manual “The symbol _+ means that the preceding type may appear from 1 to many times”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

both Measures doubled: (1, 20, 2) and (2, 40, 4).

script.vtl
define operator twice (ds dataset { measure<integer> _+ })
    returns dataset is
        ds * 2
end operator;

DS_r := twice(DS_1);
Input DS_1
Id_1Me_1Me_2
1101
2202
Expected DS_r
Id_1Me_1Me_2
1202
2404

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

Zero or more measures 🟢 pandas ✅ · DuckDB ✅
Tests:

the multiplicity modifier _*, dataset { measure<integer> _* }, with the one integer Measure of DS_1.

Manual:

define operator: multiplicityModifier ::= _ { + | * }, and in the User Manual “The symbol _* means that the preceding type may appear from 0 to many times”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_1 * 2 on each data point: (1, 20) and (2, 40).

script.vtl
define operator twice (ds dataset { measure<integer> _* })
    returns dataset is
        ds * 2
end operator;

DS_r := twice(DS_1);
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1
120
240

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

r <ruleset type> 🟢 · datapoint ruleset, hierarchical ruleset → operator

Datapoint type 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of the ruleset type datapoint, passed DPR_1 and used in check_datapoint.

Manual:

define operator: dpRuleset ::= datapoint | datapoint_on_valuedomains ... | datapoint_on_variables ..., where datapoint is any datapoint ruleset. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

from check_datapoint with all: ruleid 1, the unnamed rule’s order number, bool_var true for 10 and false for -5, and null errorcode and errorlevel. ruleid and errorcode are Strings as in the manual’s examples, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

script.vtl
define datapoint ruleset DPR_1 (variable Me_1) is
    Me_1 >= 0
end datapoint ruleset;

define operator check_positive (ds dataset, dpr datapoint)
    returns dataset is
        check_datapoint(ds, dpr all)
end operator;

DS_r := check_positive(DS_1, DPR_1);
Input DS_1
Id_1Me_1
110
2-5
Expected DS_r
Id_1ruleidbool_varerrorcodeerrorlevel
11true
21false

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

Datapoint on variables type 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of the ruleset type datapoint_on_variables, passed DPR_1, which is defined on the variable Me_1.

Manual:

define operator: dpRuleset ::= ... | datapoint_on_variables ..., the datapoint rulesets defined on variables (User Manual, Ruleset Types). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

from check_datapoint with all: ruleid 1, the unnamed rule’s order number, bool_var true for 10 and false for -5, and null errorcode and errorlevel. ruleid and errorcode are Strings as in the manual’s examples, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

script.vtl
define datapoint ruleset DPR_1 (variable Me_1) is
    Me_1 >= 0
end datapoint ruleset;

define operator check_positive (ds dataset, dpr datapoint_on_variables)
    returns dataset is
        check_datapoint(ds, dpr all)
end operator;

DS_r := check_positive(DS_1, DPR_1);
Input DS_1
Id_1Me_1
110
2-5
Expected DS_r
Id_1ruleidbool_varerrorcodeerrorlevel
11true
21false

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

Datapoint on valuedomains type 🛡️ pandas 🛡 1-2-22 · DuckDB 🛡 1-2-22

SemanticError 1-2-22: No Value Domains have been defined. Please check transformation with output Dataset DS_r

Tests:

a parameter of type datapoint_on_valuedomains, passed DPR_1, on the value domain VD_AMOUNT that components Me_1 binds.

Manual:

define operator: dpRuleset ::= ... | datapoint_on_valuedomains ..., and in check_datapoint, “If dpr is defined on Value Domains then it is mandatory to specify listComp”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

from check_datapoint with all: ruleid 1, the unnamed rule’s order number, bool_var true for 10 and false for -5, and null errorcode and errorlevel. ruleid and errorcode are Strings as in the manual’s examples, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

Finding:

VD_AMOUNT, the integer amounts, has no file: a vtlengine value-domain file holds only a list of values, and vtlengine’s loader ignores the variables and domains of its structure schema.

script.vtl
define datapoint ruleset DPR_1 (valuedomain VD_AMOUNT) is
    VD_AMOUNT >= 0
end datapoint ruleset;

define operator check_positive (ds dataset, dpr datapoint_on_valuedomains)
    returns dataset is
        check_datapoint(ds, dpr components Me_1 all)
end operator;

DS_r := check_positive(DS_1, DPR_1);
Input DS_1
Id_1Me_1
110
2-5
Expected DS_r
Id_1ruleidbool_varerrorcodeerrorlevel
11true
21false

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

Generic ruleset type 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of the generic type ruleset, passed the datapoint ruleset DPR_1.

Manual:

define operator: rulesetType ::= { ruleset | dpRuleset | hrRuleset }, and in the User Manual, Ruleset Types, “Their super-type is ruleset”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

from check_datapoint with all: ruleid 1, the unnamed rule’s order number, bool_var true for 10 and false for -5, and null errorcode and errorlevel. ruleid and errorcode are Strings as in the manual’s examples, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

script.vtl
define datapoint ruleset DPR_1 (variable Me_1) is
    Me_1 >= 0
end datapoint ruleset;

define operator check_positive (ds dataset, dpr ruleset)
    returns dataset is
        check_datapoint(ds, dpr all)
end operator;

DS_r := check_positive(DS_1, DPR_1);
Input DS_1
Id_1Me_1
110
2-5
Expected DS_r
Id_1ruleidbool_varerrorcodeerrorlevel
11true
21false

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

Hierarchical type 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of the ruleset type hierarchical, passed HR_1 and used in check_hierarchy.

Manual:

define operator: hrRuleset ::= hierarchical | hierarchical_on_valuedomains ... | hierarchical_on_variables ..., where hierarchical is any hierarchical ruleset. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

with the defaults non_null and dataset and the output all of check_hierarchy, A = B + C holds, 10 = 4 + 6: bool_var true, imbalance 0, ruleid 1 and null errorcode and errorlevel. imbalance is a Number like Me_1, ruleid and errorcode Strings, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

script.vtl
define hierarchical ruleset HR_1 (variable rule Id_2) is
    A = B + C
end hierarchical ruleset;

define operator check_total (ds dataset, hr hierarchical)
    returns dataset is
        check_hierarchy(ds, hr rule Id_2 all)
end operator;

DS_r := check_total(DS_1, HR_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B4
1C6
Expected DS_r
Id_1Id_2ruleidbool_varimbalanceerrorcodeerrorlevel
1A1true0

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

Hierarchical on variables type 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of the ruleset type hierarchical_on_variables, passed HR_1, which is defined on the variable Id_2.

Manual:

define operator: hrRuleset ::= ... | hierarchical_on_variables ..., the hierarchical rulesets defined on variables (User Manual, Ruleset Types). The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

with the defaults non_null and dataset and the output all of check_hierarchy, A = B + C holds, 10 = 4 + 6: bool_var true, imbalance 0, ruleid 1 and null errorcode and errorlevel. imbalance is a Number like Me_1, ruleid and errorcode Strings, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

script.vtl
define hierarchical ruleset HR_1 (variable rule Id_2) is
    A = B + C
end hierarchical ruleset;

define operator check_total (ds dataset, hr hierarchical_on_variables)
    returns dataset is
        check_hierarchy(ds, hr rule Id_2 all)
end operator;

DS_r := check_total(DS_1, HR_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B4
1C6
Expected DS_r
Id_1Id_2ruleidbool_varimbalanceerrorcodeerrorlevel
1A1true0

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

Hierarchical on valuedomains type 🟢 pandas ✅ · DuckDB ✅
Tests:

a parameter of type hierarchical_on_valuedomains, passed HR_1, on the value domain VD_ITEM that rule Id_2 binds.

Manual:

define operator: hrRuleset ::= ... | hierarchical_on_valuedomains ..., and in check_hierarchy, on Value Domains “it is mandatory to specify the … rule parameters”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

with the defaults non_null and dataset and the output all of check_hierarchy, A = B + C holds, 10 = 4 + 6: bool_var true, imbalance 0, ruleid 1 and null errorcode and errorlevel. imbalance is a Number like Me_1, ruleid and errorcode Strings, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

Finding:

vtlengine’s loader ignores the variables and domains of its structure schema, so only the call binds Id_2 to VD_ITEM.

script.vtl
define hierarchical ruleset HR_1 (valuedomain rule VD_ITEM) is
    A = B + C
end hierarchical ruleset;

define operator check_total (ds dataset, hr hierarchical_on_valuedomains)
    returns dataset is
        check_hierarchy(ds, hr rule Id_2 all)
end operator;

DS_r := check_total(DS_1, HR_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B4
1C6
Expected DS_r
Id_1Id_2ruleidbool_varimbalanceerrorcodeerrorlevel
1A1true0

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

y <type> default … 🟢 · integer → operator

Last argument omitted 🟢 pandas ✅ · DuckDB ✅
Tests:

add(SC_1) with SC_1 = 1 on add (x integer, y integer default 10): the last argument is left out.

Manual:

define operator: “If parameterDefaultValue is specified then the parameter is optional”, and in the call “One or more optional operands in the last positions can be simply omitted”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 11, an Integer: y takes its default, 1 + 10.

script.vtl
define operator add (x integer, y integer default 10)
    returns integer is
        x + y
end operator;

SC_r := add(SC_1);
Input scalars
SC_1
1
Expected scalars

Name

Type

Value

SC_r

Integer

11

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

Underscore for the argument 🟢 pandas ✅ · DuckDB ✅
Tests:

add(SC_1, _) with SC_1 = 1 on add (x integer, y integer default 10): _ stands for the argument of y.

Manual:

define operator: “If parameterDefaultValue is specified then the parameter is optional”, and in the call an underscore “can be used to denote that the value for an optional operand is omitted”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 11, an Integer: y takes its default, 1 + 10.

script.vtl
define operator add (x integer, y integer default 10)
    returns integer is
        x + y
end operator;

SC_r := add(SC_1, _);
Input scalars
SC_1
1
Expected scalars

Name

Type

Value

SC_r

Integer

11

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

Return type

no returns 🟢 · any scalar → operator

Type of the body 🟢 pandas ✅ · DuckDB ✅
Tests:

an operator with no returns, add_one (x integer) is x + 1, called as add_one(SC_1) with SC_1 = 2.

Manual:

define operator: “If outputType is omitted then the type returned by the operatorBody expression is assumed”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 3, an Integer, the type of x + 1.

script.vtl
define operator add_one (x integer) is
    x + 1
end operator;

SC_r := add_one(SC_1);
Input scalars
SC_1
2
Expected scalars

Name

Type

Value

SC_r

Integer

3

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

returns <scalar type> 🟢 · integer → operator

Larger of two integers 🟢 pandas ✅ · DuckDB ✅
Tests:

the operator of the page’s Example 1, called as max1(SC_1, SC_2) with SC_1 = 2 and SC_2 = 3, with returns integer. The page writes returns boolean, but if x > y then x else y returns an integer parameter: a slip that is only noted, as the page has no example data to correct.

Manual:

define operator: “if outputType is specified then the type of operatorBody must be compatible with outputType”. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

SC_r = 3, an Integer: 2 > 3 is false, so the result is y.

script.vtl
define operator max1 (x integer, y integer)
    returns integer is
        if x > y then x else y
end operator;

SC_r := max1(SC_1, SC_2);
Input scalars
SC_1SC_2
23
Expected scalars

Name

Type

Value

SC_r

Integer

3

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

returns component<…> 🟢 · integer → operator

Component in calc 🟢 pandas ✅ · DuckDB ✅
Tests:

an operator that returns component<integer>, called inside calc with the Measure Me_1.

Manual:

define operator: outputParameterType ::= scalarType | componentType | datasetType. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_2 = Me_1 + 1, a new Measure that calc adds: (1, 10, 11) and (2, 20, 21).

script.vtl
define operator add_one (c component<integer>)
    returns component<integer> is
        c + 1
end operator;

DS_r := DS_1[calc Me_2 := add_one(Me_1)];
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1Me_2
11011
22021

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

returns dataset 🟢 · any scalar → operator

Every measure plus one 🟢 pandas ✅ · DuckDB ✅
Tests:

an operator that returns dataset, called with DS_1.

Manual:

define operator: outputParameterType ::= scalarType | componentType | datasetType. The script ends with end operator, as the page’s examples and the grammar do; its syntax line writes end define operator.

Expected:

Me_1 + 1 on each data point, as “the operator is applied to the values of all the Measures”: (1, 11) and (2, 21).

script.vtl
define operator add_one (ds dataset)
    returns dataset is
        ds + 1
end operator;

DS_r := add_one(DS_1);
Input DS_1
Id_1Me_1
110
220
Expected DS_r
Id_1Me_1
111
221

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