String length · length
---
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["String length · length<br/>🟢3"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds["length(DS)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp["length(comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc["length(sc)"]:::ok
end
O --- G_ds
O --- G_comp
O --- G_sc
style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
click v_ds href "#form-ds"
click v_comp href "#form-comp"
click v_sc href "#form-sc"
Types
Takes string · Gives integer
Comes from · string — 13 operators in 3 blocks 🟢13
General purpose operators (2) 🟢2
String operators (8) 🟢8
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
Goes to · integer — 44 operators in 8 blocks 🟢44
General purpose operators (1) 🟢1
String operators (2) 🟢2
Numeric operators (18) 🟢18
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 — 46 operators in 8 blocks 🟢46
General purpose operators (6) 🟢6
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
length(DS) 🟢 · string → integer
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
length(DS_1)on a dataset with one String measure, which becomes the Integer measureint_var; one value is null.- Manual:
String length, Example 1, output verbatim: “Returns the length of a string.” For a data set, “
lengthreturns a dataset with a single measure int_var of typeinteger.”- Expected:
int_varis 5 forhelloand null for the null value. A null operand gives a null result: “most of the scalar operations (arithmetic, logical, and others) return null when any of their arguments is null” (User Manual).
DS_r := length(DS_1);
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | hello |
| 2 | B |
| Id_1 | Id_2 | int_var |
|---|---|---|
| 1 | A | 5 |
| 2 | B |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
length(comp) 🟢 · string → integer
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
length(Me_1)insidecalc, where the new measureMe_2takes the length; one value is null.- Manual:
String length, Example 2, output verbatim: “Returns the length of a string.”
- Expected:
Me_2is 5 forhelloand null for the nullMe_1;Me_1is kept. A null operand gives a null result: “most of the scalar operations (arithmetic, logical, and others) return null when any of their arguments is null” (User Manual).
DS_r:= DS_1[calc Me_2:=length(Me_1)];
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | hello |
| 2 | B |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | hello | 5 |
| 2 | B |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Manual example 3 🟢 pandas ✅ · DuckDB ✅
- Tests:
two
lengthcalls in onecalconDS_2, whereMe_1is null in one data point.- Manual:
String length, Example 3, output verbatim: “Returns the length of a string.”
- Expected:
Me_10is 5 and null, andMe_20is 5 and 2;Me_1andMe_2are kept. A null operand gives a null result: “most of the scalar operations (arithmetic, logical, and others) return null when any of their arguments is null” (User Manual).
DS_r := DS_2 [calc Me_10:= length(Me_1), Me_20:=length(Me_2)];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | hello | world |
| 2 | B | hi |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_10 | Me_20 |
|---|---|---|---|---|---|
| 1 | A | hello | world | 5 | 5 |
| 2 | B | hi | 2 |
Files: script.vtl · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
length(sc) 🟢 · string → integer
Punctuation and space counted 🟢 pandas ✅ · DuckDB ✅
- Tests:
length(SC_1)withSC_1=Hello, World!, a string with a comma, a space and an exclamation mark.- Manual:
String length: “Returns the length of a string.”, and
length("Hello, World!")gives13.- Expected:
SC_ris 13, an Integer:Hellois 5,", "is 2,Worldis 5 and!is 1.
SC_r := length(SC_1);
| SC_1 |
|---|
| Hello, World! |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
Empty string 🟢 pandas ✅ · DuckDB ✅
- Tests:
lengthof the empty string.- Manual:
String length: “Returns the length of a string.”, and
length("")gives0.- Expected:
SC_ris 0, an Integer.
SC_r := length("");
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · expected/scalars.json · example page ↗