Evaluation of an external routine · eval
---
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
||Whitespace removal trimLeading whitespace removal ltrimTrailing whitespace removal rtrimUpper case conversion upperLower case conversion lowerSub-string extraction substrString pattern replacement replaceString pattern location instrString length lengthString distances string_distanceNumeric 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
Forms
eval(R(DS)) 🟢 · external routine, any scalar → any type
Sql query on dataset 🟢 pandas ✅ · DuckDB ✅
- Tests:
evalof a SQL routine on a dataset, with the structure of its result declared inreturns.- 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, withMe_120 and 40.
DS_r <- eval(SQL_1(DS_1) language "SQL" returns dataset {identifier<integer> Id_1, measure<integer> Me_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 · external_routines/SQL_1.json · example page ↗
eval(R(DS, sc)) 🟢 · external routine, any scalar → any type
Positional scalar argument 🟢 pandas ✅ · DuckDB ✅
- Tests:
evalwith 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,evalruns on data sets only, so its arguments are data sets, never scalars.
DS_r <- eval(SQL_2(DS_1, 3) language "SQL" returns dataset {identifier<integer> Id_1, measure<integer> Me_1});
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
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:
evalof a routine that returns a scalar, declaredreturns stringas in the page’seval(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” isresult :: dataset, against the Behaviour, theoutputTypeand 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,evalruns on data sets only and returns a data set, never a scalar.
SC_r <- eval(SQL_3(DS_1) language "SQL" returns string);
| Id_1 | Me_1 |
|---|---|
| 1 | A |
| 2 | C |
| 3 | B |
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:
evalinsidecalc, after the page’sDS_1 [calc Me := eval ( f (Me ) language "Java" returns integer) ]: the routine runs on theMe_1of 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 incalc, 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,evalruns on data sets only, never inside a component expression.
DS_r <- DS_1[calc Me_2 := eval(SQL_4(Me_1) language "SQL" returns integer)];
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
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 ↗