define datapoint ruleset

🟢 4 of 5 forms all ok, 1 refused · 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 datapoint ruleset<br/>🟢4 🛡️1"]:::ok
    subgraph G_b1["Signature"]
        direction LR
        v_valuedomain["(valuedomain VD #91;as alias#93;, …)"]:::refused
        v_variable["(variable V #91;as alias#93;, …)"]:::ok
    end
    subgraph G_b2["Body"]
        direction LR
        v_unconditioned_rule["consequent"]:::ok
        v_conditioned_rule["when … then …"]:::ok
        v_rule_options["#91;name :#93; … #91;errorcode …#93; #91;errorlevel …#93;"]:::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_valuedomain href "#form-valuedomain"
    click v_variable href "#form-variable"
    click v_unconditioned_rule href "#form-unconditioned-rule"
    click v_conditioned_rule href "#form-conditioned-rule"
    click v_rule_options href "#form-rule-options"
    

Types

Takes integer, string, boolean, value domain · Gives datapoint ruleset

Comes from · integer, string, boolean — 44 operators in 8 blocks 🟢44
General purpose operators (2) 🟢2
String operators (10) 🟢10
Numeric operators (4) 🟢4
Comparison operators (12) 🟢12
Boolean operators (4) 🟢4
Time operators (7) 🟢7
Aggregate and Analytic operators (2) 🟢2
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 37 operators in 8 blocks 🟢37
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Time operators (3) 🟢3
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Clause operators (9) 🟢9

Comes from · value domain: none

Goes to · datapoint ruleset — 2 operators in 2 blocks 🟢2
Data validation operators (1) 🟢1
Definitions (VTL-DL) (1) 🟢1

Forms

Signature

(valuedomain VD [as alias], …) 🛡️ · boolean, value domain → datapoint ruleset

Domains bound to components 🛡️ pandas 🛡 1-2-8 · DuckDB 🛡 1-2-8

SemanticError 1-2-8: Missing value domain 'VD_AMOUNT' definition, please provide an structure. Please check transformation with output Dataset DS_r

Tests:

a ruleset on the value domains VD_FLOW and VD_AMOUNT, bound to Id_2 and Me_1 with components in check_datapoint.

Manual:

define datapoint ruleset: “If an alias is not specified then the name of the Value Domain … is used in the body of the rules”, and in check_datapoint, “If dpr is defined on Value Domains then it is mandatory to specify listComp”.

Expected:

ruleid 1 and bool_var true, false and true for (CREDIT, 10), (CREDIT, -5) and (DEBIT, -2), the last as its antecedent is false. errorcode and errorlevel are null, ruleid and errorcode Strings, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

Finding:

VD_AMOUNT, the integer amounts, has no file, as a vtlengine value-domain file lists values only, and the loader ignores the variables and domains of its structure schema.

script.vtl
define datapoint ruleset DPR_1 (valuedomain VD_FLOW, VD_AMOUNT) is
    when VD_FLOW = "CREDIT" then VD_AMOUNT >= 0
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 components Id_2, Me_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2CREDIT-5
3DEBIT-2
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2CREDIT1false
3DEBIT1true

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

Domain aliases in the rule 🛡️ pandas 🛡 1-2-8 · DuckDB 🛡 1-2-8

SemanticError 1-2-8: Missing value domain 'VD_AMOUNT' definition, please provide an structure. Please check transformation with output Dataset DS_r

Tests:

the value domains with the aliases F and A, which the rule uses, bound to Id_2 and Me_1 with components.

Manual:

define datapoint ruleset: the alias is “an (optional) alias assigned to a Value Domain and valid only within the Ruleset”, and in check_datapoint, “If dpr is defined on Value Domains then it is mandatory to specify listComp”.

Expected:

ruleid 1 and bool_var true, false and true for (CREDIT, 10), (CREDIT, -5) and (DEBIT, -2), the last as its antecedent is false. errorcode and errorlevel are null, ruleid and errorcode Strings, and errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

Finding:

VD_AMOUNT, the integer amounts, has no file, as a vtlengine value-domain file lists values only, and the loader ignores the variables and domains of its structure schema.

script.vtl
define datapoint ruleset DPR_1 (valuedomain VD_FLOW as F, VD_AMOUNT as A) is
    when F = "CREDIT" then A >= 0
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 components Id_2, Me_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2CREDIT-5
3DEBIT-2
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2CREDIT1false
3DEBIT1true

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

(variable V [as alias], …) 🟢 · boolean → datapoint ruleset

Variables of the dataset 🟢 pandas ✅ · DuckDB ✅
Tests:

a datapoint ruleset on the variables Id_2 and Me_1, components of DS_1, so check_datapoint needs no components.

Manual:

define datapoint ruleset: “If variable is specified then the Ruleset is applicable to Data Sets having the specified Variables as Components”.

Expected:

ruleid 1, the unnamed rule’s order number, and bool_var true for (CREDIT, 10), false for (CREDIT, -5) and true for (DEBIT, -2), whose antecedent is false. errorcode and errorlevel are null, ruleid and errorcode 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 Id_2, Me_1) is
    when Id_2 = "CREDIT" then Me_1 >= 0
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2CREDIT-5
3DEBIT-2
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2CREDIT1false
3DEBIT1true

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

Variable aliases in the rule 🟢 pandas ✅ · DuckDB ✅
Tests:

the variables with the aliases F and A, which the rule uses; check_datapoint needs no components.

Manual:

define datapoint ruleset: the alias is “an (optional) alias assigned to a Variable and valid only within the Ruleset”.

Expected:

ruleid 1, the unnamed rule’s order number, and bool_var true for (CREDIT, 10), false for (CREDIT, -5) and true for (DEBIT, -2), whose antecedent is false. errorcode and errorlevel are null, ruleid and errorcode 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 Id_2 as F, Me_1 as A) is
    when F = "CREDIT" then A >= 0
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2CREDIT-5
3DEBIT-2
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2CREDIT1false
3DEBIT1true

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

Body

consequent 🟢 · boolean → datapoint ruleset

Consequent alone 🟢 pandas ✅ · DuckDB ✅
Tests:

a rule with no antecedent, Me_1 >= 0.

Manual:

define datapoint ruleset: “In case the antecedentCondition is absent then it is assumed to be always true, therefore the consequentCondition is expected to evaluate to true for all the Data Points”.

Expected:

ruleid 1, the order number of the unnamed rule, and bool_var true for 10 and false for -5. errorcode and errorlevel are null, ruleid and errorcode 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;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2DEBIT-5
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2DEBIT1false

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

when … then … 🟢 · boolean → datapoint ruleset

Three cases of the implication 🟢 pandas ✅ · DuckDB ✅
Tests:

when Id_2 = "CREDIT" then Me_1 >= 0 on three data points, one for each case of the implication.

Manual:

define datapoint ruleset: “if the antecedentCondition evaluates to false, the consequentCondition does not applies and is not evaluated at all, and the result is considered as valid (true)”.

Expected:

ruleid 1, the unnamed rule’s order number, and bool_var true for (CREDIT, 10), false for (CREDIT, -5) and true for (DEBIT, -2), whose antecedent is false. errorcode and errorlevel are null, ruleid and errorcode 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 Id_2, Me_1) is
    when Id_2 = "CREDIT" then Me_1 >= 0
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2CREDIT-5
3DEBIT-2
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2CREDIT1false
3DEBIT1true

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

[name :] … [errorcode …] [errorlevel …] 🟢 · integer, string, boolean → datapoint ruleset

Two named rules 🟢 pandas ✅ · DuckDB ✅
Tests:

two named rules, R_CREDIT and R_DEBIT, on two data points.

Manual:

define datapoint ruleset: “If the Ruleset is used for validation then the ruleName identifies the validation results of the various Rules of the Ruleset”, and “Either ruleName is specified for all the Rules of the Ruleset or for none”.

Expected:

one result per data point and rule, named in ruleid: R_CREDIT is true for both, and R_DEBIT true for (CREDIT, 10), whose antecedent is false, and false for (DEBIT, 5). errorcode and errorlevel are null, ruleid and errorcode 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 Id_2, Me_1) is
    R_CREDIT : when Id_2 = "CREDIT" then Me_1 >= 0;
    R_DEBIT : when Id_2 = "DEBIT" then Me_1 <= 0
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2DEBIT5
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDITR_CREDITtrue
2DEBITR_CREDITtrue
1CREDITR_DEBITtrue
2DEBITR_DEBITfalse

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

Rules named by their order 🟢 pandas ✅ · DuckDB ✅
Tests:

two unnamed rules on two data points.

Manual:

define datapoint ruleset: “The ruleName is optional and, if not specified, is assumed to be the progressive order number of the Rule in the Ruleset”.

Expected:

ruleid 1 and 2: rule 1 is true for both data points, and rule 2 true for (CREDIT, 10), whose antecedent is false, and false for (DEBIT, 5). errorcode and errorlevel are null, ruleid and errorcode 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 Id_2, Me_1) is
    when Id_2 = "CREDIT" then Me_1 >= 0;
    when Id_2 = "DEBIT" then Me_1 <= 0
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2DEBIT5
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2DEBIT1true
1CREDIT2true
2DEBIT2false

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

Errorcode on the invalid point 🟢 pandas ✅ · DuckDB ✅
Tests:

when Id_2 = "CREDIT" then Me_1 >= 0 errorcode "NEG_CREDIT".

Manual:

define datapoint ruleset: the error code is “a literal denoting the error code associated to the rule, to be assigned to the possible non-valid results”, and in check_datapoint “if the Measure bool_var is true or null then errorcode is null”.

Expected:

ruleid 1 and bool_var true, false and true for (CREDIT, 10), (CREDIT, -5) and (DEBIT, -2), with errorcode NEG_CREDIT only on the false one. ruleid and errorcode are Strings as in the manual’s examples, and the null errorlevel Integer, the manual’s default without errorlevel_vd (#1256).

script.vtl
define datapoint ruleset DPR_1 (variable Id_2, Me_1) is
    when Id_2 = "CREDIT" then Me_1 >= 0 errorcode "NEG_CREDIT"
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2CREDIT-5
3DEBIT-2
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2CREDIT1falseNEG_CREDIT
3DEBIT1true

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

Errorlevel on the invalid point 🟢 pandas ✅ · DuckDB ✅
Tests:

when Id_2 = "CREDIT" then Me_1 >= 0 errorlevel 5.

Manual:

define datapoint ruleset: the error level is “a literal denoting the error level (severity) associated to the rule, to be assigned to the possible non-valid results”, and in check it “must be a valid value of the errorlevel_vd Value Domain (or integer if the errorcode_vd Value Domain is not found)”.

Expected:

errorlevel 5 only on the false data point, (CREDIT, -5), typed Integer: no errorlevel_vd is defined here, and the manual’s examples of check, check_datapoint and check_hierarchy type it Integer. ruleid 1 and the null errorcode are Strings.

script.vtl
define datapoint ruleset DPR_1 (variable Id_2, Me_1) is
    when Id_2 = "CREDIT" then Me_1 >= 0 errorlevel 5
end datapoint ruleset;

DS_r := check_datapoint(DS_1, DPR_1 all);
Input DS_1
Id_1Id_2Me_1
1CREDIT10
2CREDIT-5
3DEBIT-2
Expected DS_r
Id_1Id_2ruleidbool_varerrorcodeerrorlevel
1CREDIT1true
2CREDIT1false5
3DEBIT1true

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