Evaluation of an external routine · eval

🟢 4 of 4 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc3 (9e1c81a6) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
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["Evaluation of an external routine · eval<br/>🟢4"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_sql_dataset["eval(R(DS))"]:::ok
        v_sql_dataset_scalar_arg["eval(R(DS, sc))"]:::ok
        v_scalar_return["eval(R(DS) returns string)"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp["DS#91;calc Me #58;#61; eval(R(comp))#93;"]:::ok
    end
    O --- G_ds
    O --- G_comp
    style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
    style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
    click v_sql_dataset href "#form-sql-dataset"
    click v_sql_dataset_scalar_arg href "#form-sql-dataset-scalar-arg"
    click v_scalar_return href "#form-scalar-return"
    click v_comp href "#form-comp"
    

Types

Takes external routine, any scalar · Gives integer, string, any type

Comes from: any operator that returns a value

Comes from · external routine: none

Goes to: whatever takes its input's type

Goes to · integer, string — 54 operators in 9 blocks 🟢54
General purpose operators (1) 🟢1
String operators (11) 🟢11
Numeric operators (18) 🟢18
Comparison operators (1) 🟢1
Time operators (6) 🟢6
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (10) 🟢10
Data validation operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 45 operators in 8 blocks 🟢45
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (8) 🟢8
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Clause operators (9) 🟢9

Forms

eval(R(DS)) 🟢 · external routine, any scalar → any type

Sql query on dataset 🟢 pandas ✅ · DuckDB ✅
Tests:

eval of a SQL routine on a dataset, with the structure of its result declared in returns.

Manual:

Evaluation of an external routine: “The eval operator invokes an external, non-VTL routine, and returns its result as a Data Set or a scalar”, and “The result of an expression containing eval must be persistent”, so the script uses <-.

Expected:

vtlengine reads the routine as the SQL query of external_routines/SQL_1.json, SELECT Id_1, Me_1 * 2 AS Me_1 FROM DS_1: the declared structure, with Me_1 20 and 40.

script.vtl
DS_r <- eval(SQL_1(DS_1) language "SQL" returns dataset {identifier<integer> Id_1, measure<integer> Me_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 · external_routines/SQL_1.json · example page ↗

eval(R(DS, sc)) 🟢 · external routine, any scalar → any type

Positional scalar argument 🟢 pandas ✅ · DuckDB ✅
Tests:

eval with a dataset and a scalar argument, which the routine reads by its position.

Manual:

Evaluation of an external routine: an argument “can be a name or a value of a VTL artefacts”, and “The arguments passed to the routine correspond to the parameters of the invoked external routine in positional order”.

Expected:

the error 1-2-23, “{pos} operand must be a Dataset”: by a team decision, eval runs on data sets only, so its arguments are data sets, never scalars.

script.vtl
DS_r <- eval(SQL_2(DS_1, 3) language "SQL" returns dataset {identifier<integer> Id_1, measure<integer> Me_1});
Input DS_1
Id_1Me_1
110
220

Expected error 1-2-23: {pos} operand must be a Dataset.

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · external_routines/SQL_2.json · example page ↗

eval(R(DS) returns string) 🟢 · external routine, any scalar → string

String result 🟢 pandas ✅ · DuckDB ✅
Tests:

eval of a routine that returns a scalar, declared returns string as in the page’s eval(routine1(DS_1) language "PL/SQL" returns string).

Manual:

Evaluation of an external routine: eval “returns its result as a Data Set or a scalar”, and its result “must be persistent”, so the script uses <-. Its “Result type” is result :: dataset, against the Behaviour, the outputType and the page’s syntax example.

Expected:

the error 1-3-2-1, “Eval could not be called without a {option} type definition”: by a team decision, eval runs on data sets only and returns a data set, never a scalar.

script.vtl
SC_r <- eval(SQL_3(DS_1) language "SQL" returns string);
Input DS_1
Id_1Me_1
1A
2C
3B

Expected error 1-3-2-1: Eval could not be called without a {option} type definition.

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · external_routines/SQL_3.json · example page ↗

DS[calc Me := eval(R(comp))] 🟢 · external routine, any scalar → integer

Inside calc 🟢 pandas ✅ · DuckDB ✅
Tests:

eval inside calc, after the page’s DS_1 [calc Me := eval ( f (Me ) language "Java" returns integer) ]: the routine runs on the Me_1 of each data point.

Manual:

Evaluation of an external routine: eval “returns its result as a Data Set or a scalar”, of a type “given in the invocation”. The page contradicts itself: “eval cannot be nested as the operand of another operation”, its result “must be persistent”, “This is not a scalar operation” and its “Result type” is result :: dataset, yet its own example nests it in calc, assigns it with := and gives an integer per data point; the example follows that example, with <-.

Expected:

the error 1-3-2-5, “At op eval: Eval in component execution is not supported, it only applies to Data Sets”: by a team decision, eval runs on data sets only, never inside a component expression.

script.vtl
DS_r <- DS_1[calc Me_2 := eval(SQL_4(Me_1) language "SQL" returns integer)];
Input DS_1
Id_1Me_1
110
220

Expected error 1-3-2-5: At op eval: Eval in component execution is not supported, it only applies to Data Sets.

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · external_routines/SQL_4.json · example page ↗