define operator
---
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 calloperatorName ( { argument { , argument }* } )passes none. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 42, an Integer:6 * 7.
define operator answer ()
returns integer is
6 * 7
end operator;
SC_r := answer();
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 asadd_one(SC_1)withSC_1= 2.- Manual:
define operator: a parameter type is “a VTL data type” (
basicScalarType ::= ... integer ...). The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 3, an Integer:2 + 1.
define operator add_one (x integer)
returns integer is
x + 1
end operator;
SC_r := add_one(SC_1);
| SC_1 |
|---|
| 2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 astwice(SC_1)withSC_1= 1.25.- Manual:
define operator: a parameter type is “a VTL data type” (
basicScalarType ::= ... number ...). The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 2.5, a Number:1.25 * 2.
define operator twice (x number)
returns number is
x * 2
end operator;
SC_r := twice(SC_1);
| SC_1 |
|---|
| 1.25 |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
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 aswith_suffix(SC_1)withSC_1=A.- Manual:
define operator: a parameter type is “a VTL data type” (
basicScalarType ::= ... string ...). The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = "A_B", a String:"A" || "_B".
define operator with_suffix (x string)
returns string is
x || "_B"
end operator;
SC_r := with_suffix(SC_1);
| SC_1 |
|---|
| A |
Name |
Type |
Value |
|---|---|---|
|
String |
|
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 asnegation(SC_1)withSC_1= true.- Manual:
define operator: a parameter type is “a VTL data type” (
basicScalarType ::= ... boolean ...). The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = false, a Boolean:not true.
define operator negation (x boolean)
returns boolean is
not x
end operator;
SC_r := negation(SC_1);
| SC_1 |
|---|
| true |
Name |
Type |
Value |
|---|---|---|
|
Boolean |
|
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 assame_date(SC_1)with the DateSC_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 2020-01-15, a Date: the body returns its argument.
define operator same_date (x date)
returns date is
x
end operator;
SC_r := same_date(SC_1);
| SC_1 |
|---|
| 2020-01-15 |
Name |
Type |
Value |
|---|---|---|
|
Date |
|
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 assame_period(SC_1)with the Time_PeriodSC_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 2020Q1, a Time_Period: the body returns its argument.
define operator same_period (x time_period)
returns time_period is
x
end operator;
SC_r := same_period(SC_1);
| SC_1 |
|---|
| 2020Q1 |
Name |
Type |
Value |
|---|---|---|
|
Time_Period |
|
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 assame_time(SC_1)with the TimeSC_1=2020-01-01/2020-12-31, the year 2020 in the manual’s representationYYYY-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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 2020-01-01/2020-12-31, a Time: the body returns its argument.
define operator same_time (x time)
returns time is
x
end operator;
SC_r := same_time(SC_1);
| SC_1 |
|---|
| 2020-01-01/2020-12-31 |
Name |
Type |
Value |
|---|---|---|
|
Time |
|
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 assame_duration(SC_1)with the DurationSC_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = M, a Duration: the body returns its argument.
define operator same_duration (x duration)
returns duration is
x
end operator;
SC_r := same_duration(SC_1);
| SC_1 |
|---|
| M |
Name |
Type |
Value |
|---|---|---|
|
Duration |
|
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, withreturns scalar, called assame_scalar(SC_1)with the IntegerSC_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 5, an Integer: the body returns its argument, which keeps its type, asreturns scalarallows any scalar type.
define operator same_scalar (x scalar)
returns scalar is
x
end operator;
SC_r := same_scalar(SC_1);
| SC_1 |
|---|
| 5 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 stringsA,BandC, called aswith_suffix(SC_1)withSC_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = "A_X", a String:"A"is a value ofVD_1, andx || "_X"concatenates it as a string.
define operator with_suffix (x VD_1)
returns string is
x || "_X"
end operator;
SC_r := with_suffix(SC_1);
| SC_1 |
|---|
| A |
Name |
Type |
Value |
|---|---|---|
|
String |
|
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 astimes_ten(SC_1)withSC_1= 2.- Manual:
define operator:
scalarTypeConstraint ::= [ valueBooleanCondition ] | ..., a condition “expressed with reference to the fictitious variable”value, as innumber [ value >= 0 ]. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 20, an Integer:2meets the condition, and2 * 10 = 20.
define operator times_ten (x integer [value >= 0])
returns integer is
x * 10
end operator;
SC_r := times_ten(SC_1);
| SC_1 |
|---|
| 2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 astimes_ten(SC_1)withSC_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 20, an Integer:2is in the list, and2 * 10 = 20.
define operator times_ten (x integer { 1, 2, 3 })
returns integer is
x * 10
end operator;
SC_r := times_ten(SC_1);
| SC_1 |
|---|
| 2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 asadd_one(SC_1)withSC_1= 2.- Manual:
define operator:
scalarType ::= ... { { not } null }. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = 3, an Integer:2is not null, and2 + 1 = 3.
define operator add_one (x integer not null)
returns integer is
x + 1
end operator;
SC_r := add_one(SC_1);
| SC_1 |
|---|
| 2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 asis_in(SC_1, VD_AB)withSC_1=Band the value domainVD_AB(AandB) passed by its name, as the grammar takes set literals only afterinandnot_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
SC_r = true, a Boolean:"B" in sholds, asBis a value ofVD_AB.
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);
| SC_1 |
|---|
| B |
Name |
Type |
Value |
|---|---|---|
|
Boolean |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · value_domains/VD_AB.json · example page ↗
ds dataset [{ … }] 🟢 · any scalar → operator
Dataset argument 🟢 pandas ✅ · DuckDB ✅
- Tests:
a parameter of type
dataset, with no component constraint, called withDS_1.- Manual:
define operator:
datasetType ::= dataset { ... }, here without constraints: the super-type of the Data Set types, “any dataset” (User Manual). The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
Me_1 * 2on each data point, as “the operator is applied to the values of all the Measures”: (1, 20) and (2, 40).
define operator twice (ds dataset)
returns dataset is
ds * 2
end operator;
DS_r := twice(DS_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_1 | Me_1 |
|---|---|
| 1 | 20 |
| 2 | 40 |
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 ofDS_1.- Manual:
define operator:
componentConstraint ::= componentType { componentName | multiplicityModifier }. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
Me_1 * 2on each data point: (1, 20) and (2, 40).
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);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_1 | Me_1 |
|---|---|
| 1 | 20 |
| 2 | 40 |
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 ofDS_1meets.- 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 asdataset { measure<number> _ }. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
Me_1 * 2on each data point: (1, 20) and (2, 40).
define operator twice (ds dataset { measure<integer> _ })
returns dataset is
ds * 2
end operator;
DS_r := twice(DS_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_1 | Me_1 |
|---|---|
| 1 | 20 |
| 2 | 40 |
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 ofDS_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
both Measures doubled: (1, 20, 2) and (2, 40, 4).
define operator twice (ds dataset { measure<integer> _+ })
returns dataset is
ds * 2
end operator;
DS_r := twice(DS_1);
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 10 | 1 |
| 2 | 20 | 2 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 20 | 2 |
| 2 | 40 | 4 |
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 ofDS_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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
Me_1 * 2on each data point: (1, 20) and (2, 40).
define operator twice (ds dataset { measure<integer> _* })
returns dataset is
ds * 2
end operator;
DS_r := twice(DS_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_1 | Me_1 |
|---|---|
| 1 | 20 |
| 2 | 40 |
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, passedDPR_1and used incheck_datapoint.- Manual:
define operator:
dpRuleset ::= datapoint | datapoint_on_valuedomains ... | datapoint_on_variables ..., wheredatapointis any datapoint ruleset. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
from
check_datapointwithall:ruleid1, the unnamed rule’s order number,bool_vartrue for 10 and false for -5, and nullerrorcodeanderrorlevel.ruleidanderrorcodeare Strings as in the manual’s examples, anderrorlevelInteger, the manual’s default without errorlevel_vd (#1256).
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);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | -5 |
| Id_1 | ruleid | bool_var | errorcode | errorlevel |
|---|---|---|---|---|
| 1 | 1 | true | ||
| 2 | 1 | false |
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, passedDPR_1, which is defined on the variableMe_1.- Manual:
define operator:
dpRuleset ::= ... | datapoint_on_variables ..., the datapoint rulesets defined on variables (User Manual, Ruleset Types). The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
from
check_datapointwithall:ruleid1, the unnamed rule’s order number,bool_vartrue for 10 and false for -5, and nullerrorcodeanderrorlevel.ruleidanderrorcodeare Strings as in the manual’s examples, anderrorlevelInteger, the manual’s default without errorlevel_vd (#1256).
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);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | -5 |
| Id_1 | ruleid | bool_var | errorcode | errorlevel |
|---|---|---|---|---|
| 1 | 1 | true | ||
| 2 | 1 | false |
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, passedDPR_1, on the value domainVD_AMOUNTthatcomponents Me_1binds.- 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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
from
check_datapointwithall:ruleid1, the unnamed rule’s order number,bool_vartrue for 10 and false for -5, and nullerrorcodeanderrorlevel.ruleidanderrorcodeare Strings as in the manual’s examples, anderrorlevelInteger, 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 thevariablesanddomainsof its structure schema.
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);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | -5 |
| Id_1 | ruleid | bool_var | errorcode | errorlevel |
|---|---|---|---|---|
| 1 | 1 | true | ||
| 2 | 1 | false |
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 rulesetDPR_1.- Manual:
define operator:
rulesetType ::= { ruleset | dpRuleset | hrRuleset }, and in the User Manual, Ruleset Types, “Their super-type is ruleset”. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
from
check_datapointwithall:ruleid1, the unnamed rule’s order number,bool_vartrue for 10 and false for -5, and nullerrorcodeanderrorlevel.ruleidanderrorcodeare Strings as in the manual’s examples, anderrorlevelInteger, the manual’s default without errorlevel_vd (#1256).
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);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | -5 |
| Id_1 | ruleid | bool_var | errorcode | errorlevel |
|---|---|---|---|---|
| 1 | 1 | true | ||
| 2 | 1 | false |
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, passedHR_1and used incheck_hierarchy.- Manual:
define operator:
hrRuleset ::= hierarchical | hierarchical_on_valuedomains ... | hierarchical_on_variables ..., wherehierarchicalis any hierarchical ruleset. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
with the defaults
non_nullanddatasetand the outputallofcheck_hierarchy,A = B + Cholds, 10 = 4 + 6:bool_vartrue,imbalance0,ruleid1 and nullerrorcodeanderrorlevel.imbalanceis a Number likeMe_1,ruleidanderrorcodeStrings, anderrorlevelInteger, the manual’s default without errorlevel_vd (#1256).
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);
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 10 |
| 1 | B | 4 |
| 1 | C | 6 |
| Id_1 | Id_2 | ruleid | bool_var | imbalance | errorcode | errorlevel |
|---|---|---|---|---|---|---|
| 1 | A | 1 | true | 0 |
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, passedHR_1, which is defined on the variableId_2.- Manual:
define operator:
hrRuleset ::= ... | hierarchical_on_variables ..., the hierarchical rulesets defined on variables (User Manual, Ruleset Types). The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
with the defaults
non_nullanddatasetand the outputallofcheck_hierarchy,A = B + Cholds, 10 = 4 + 6:bool_vartrue,imbalance0,ruleid1 and nullerrorcodeanderrorlevel.imbalanceis a Number likeMe_1,ruleidanderrorcodeStrings, anderrorlevelInteger, the manual’s default without errorlevel_vd (#1256).
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);
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 10 |
| 1 | B | 4 |
| 1 | C | 6 |
| Id_1 | Id_2 | ruleid | bool_var | imbalance | errorcode | errorlevel |
|---|---|---|---|---|---|---|
| 1 | A | 1 | true | 0 |
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, passedHR_1, on the value domainVD_ITEMthatrule Id_2binds.- 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 withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
with the defaults
non_nullanddatasetand the outputallofcheck_hierarchy,A = B + Cholds, 10 = 4 + 6:bool_vartrue,imbalance0,ruleid1 and nullerrorcodeanderrorlevel.imbalanceis a Number likeMe_1,ruleidanderrorcodeStrings, anderrorlevelInteger, the manual’s default without errorlevel_vd (#1256).- Finding:
vtlengine’s loader ignores the
variablesanddomainsof its structure schema, so only the call bindsId_2toVD_ITEM.
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);
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 10 |
| 1 | B | 4 |
| 1 | C | 6 |
| Id_1 | Id_2 | ruleid | bool_var | imbalance | errorcode | errorlevel |
|---|---|---|---|---|---|---|
| 1 | A | 1 | true | 0 |
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)withSC_1= 1 onadd (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 writesend define operator.- Expected:
SC_r = 11, an Integer:ytakes its default,1 + 10.
define operator add (x integer, y integer default 10)
returns integer is
x + y
end operator;
SC_r := add(SC_1);
| SC_1 |
|---|
| 1 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
Underscore for the argument 🟢 pandas ✅ · DuckDB ✅
- Tests:
add(SC_1, _)withSC_1= 1 onadd (x integer, y integer default 10):_stands for the argument ofy.- 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 writesend define operator.- Expected:
SC_r = 11, an Integer:ytakes its default,1 + 10.
define operator add (x integer, y integer default 10)
returns integer is
x + y
end operator;
SC_r := add(SC_1, _);
| SC_1 |
|---|
| 1 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 asadd_one(SC_1)withSC_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 writesend define operator.- Expected:
SC_r = 3, an Integer, the type ofx + 1.
define operator add_one (x integer) is
x + 1
end operator;
SC_r := add_one(SC_1);
| SC_1 |
|---|
| 2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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)withSC_1= 2 andSC_2= 3, withreturns integer. The page writesreturns boolean, butif x > y then x else yreturns 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 writesend define operator.- Expected:
SC_r = 3, an Integer:2 > 3is false, so the result isy.
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);
| SC_1 | SC_2 |
|---|---|
| 2 | 3 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
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 insidecalcwith the MeasureMe_1.- Manual:
define operator:
outputParameterType ::= scalarType | componentType | datasetType. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
Me_2 = Me_1 + 1, a new Measure thatcalcadds: (1, 10, 11) and (2, 20, 21).
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)];
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 10 | 11 |
| 2 | 20 | 21 |
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 withDS_1.- Manual:
define operator:
outputParameterType ::= scalarType | componentType | datasetType. The script ends withend operator, as the page’s examples and the grammar do; its syntax line writesend define operator.- Expected:
Me_1 + 1on each data point, as “the operator is applied to the values of all the Measures”: (1, 11) and (2, 21).
define operator add_one (ds dataset)
returns dataset is
ds + 1
end operator;
DS_r := add_one(DS_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_1 | Me_1 |
|---|---|
| 1 | 11 |
| 2 | 21 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗