User-defined operator call · name( )

🟢 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
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart LR
    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["User-defined operator call · name( )<br/>🟢4"]:::ok
    v_no_args["op()"]:::ok
    v_all_args["op(a, b)"]:::ok
    v_default_omitted["op(a)"]:::ok
    v_placeholder_arg["op(a, _, c)"]:::ok
    v_no_args --- O
    v_all_args --- O
    O --- v_default_omitted
    O --- v_placeholder_arg
    click v_no_args href "#form-no-args"
    click v_all_args href "#form-all-args"
    click v_default_omitted href "#form-default-omitted"
    click v_placeholder_arg href "#form-placeholder-arg"
    

Types

Takes operator, any scalar · Gives any type

Comes from: any operator that returns a value

Comes from · operator — 1 operator in 1 block 🟢1
Definitions (VTL-DL) (1) 🟢1

Goes to: whatever takes its input's type

Forms

op() 🟢 · operator → any type

Empty argument list 🟢 pandas ✅ · DuckDB ✅
Tests:

A call with no arguments, answer(), of an operator defined with no parameters.

Manual:

User-defined operator call: the syntax operatorName ( { argument { , argument }* } ) makes the whole list of arguments optional, and the define operator syntax does the same for the parameters, ( { parameter { , parameter }* } ).

Expected:

SC_r = 42, the body of the operator, an Integer.

script.vtl
define operator answer ()
  returns integer is
    42
end operator;

SC_r := answer();
Expected scalars

Name

Type

Value

SC_r

Integer

"42"

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

op(a, b) 🟢 · operator, any scalar → any type

Positional order 🟢 pandas ✅ · DuckDB ✅
Tests:

A call with every argument, diff2(SC_1, SC_2) with SC_1 = 10 and SC_2 = 3, whose body x - y tells their order apart, as the page’s max1 ( 2, 3 ) cannot.

Manual:

User-defined operator call: “The arguments passed to the operator in the invocation are associated to the corresponding parameters in positional order”. The page’s max1, which the define operator page repeats, declares returns boolean for a body that returns an integer, and the script ends its definition with end operator, as the examples there do, not with end define operator as the syntax does.

Expected:

x = 10 and y = 3, so SC_r = 7, an Integer as returns integer declares; swapped arguments would give -7.

script.vtl
define operator diff2 (x integer, y integer)
  returns integer is
    x - y
end operator;

SC_r := diff2(SC_1, SC_2);
Input scalars
SC_1SC_2
103
Expected scalars

Name

Type

Value

SC_r

Integer

"7"

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

op(a) 🟢 · operator, any scalar → any type

Trailing default 🟢 pandas ✅ · DuckDB ✅
Tests:

A call that omits its last argument, an optional one: diff2(SC_1) with SC_1 = 10.

Manual:

User-defined operator call: “One or more optional operands in the last positions can be simply omitted”, and define operator: “If parameterDefaultValue is specified then the parameter is optional”.

Expected:

y takes its default 1, so SC_r = 10 - 1 = 9, an Integer.

script.vtl
define operator diff2 (x integer, y integer default 1)
  returns integer is
    x - y
end operator;

SC_r := diff2(SC_1);
Input scalars
SC_1
10
Expected scalars

Name

Type

Value

SC_r

Integer

"9"

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

op(a, _, c) 🟢 · operator, any scalar → any type

Underscore in the middle 🟢 pandas ✅ · DuckDB ✅
Tests:

A call with _ for an optional argument in the middle, diff3(SC_1, _, SC_2) with SC_1 = 10 and SC_2 = 5, where it cannot simply be left out because z comes after it.

Manual:

User-defined operator call: “An underscore (“_”) can be used to denote that the value for an optional operand is omitted.”

Expected:

x = 10, y takes its default 1 and z = 5, so SC_r = 10 - 1 - 5 = 4, an Integer; reading 5 as y, with z at its default 100, would give -95.

script.vtl
define operator diff3 (x integer, y integer default 1, z integer default 100)
  returns integer is
    x - y - z
end operator;

SC_r := diff3(SC_1, _, SC_2);
Input scalars
SC_1SC_2
105
Expected scalars

Name

Type

Value

SC_r

Integer

"4"

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