String distances · string_distance
---
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 distances · string_distance<br/>🟢11"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_levenshtein_ds_ds["string_distance(levenshtein, DS, DS)"]:::ok
v_levenshtein_ds_sc["string_distance(levenshtein, DS, sc)"]:::ok
v_levenshtein_sc_ds["string_distance(levenshtein, sc, DS)"]:::ok
v_damerau_levenshtein_ds_ds["string_distance(damerau_levenshtein, DS, DS)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_levenshtein_comp_comp["string_distance(levenshtein, comp, comp)"]:::ok
v_levenshtein_sc_comp["string_distance(levenshtein, sc, comp)"]:::ok
v_hamming_comp_sc["string_distance(hamming, comp, sc)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_levenshtein_sc["string_distance(levenshtein, sc, sc)"]:::ok
v_damerau_levenshtein_sc["string_distance(damerau_levenshtein, sc, sc)"]:::ok
v_hamming_sc["string_distance(hamming, sc, sc)"]:::ok
v_jaro_winkler_sc["string_distance(jaro_winkler, sc, 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_levenshtein_ds_ds href "#form-levenshtein-ds-ds"
click v_levenshtein_ds_sc href "#form-levenshtein-ds-sc"
click v_levenshtein_sc_ds href "#form-levenshtein-sc-ds"
click v_levenshtein_comp_comp href "#form-levenshtein-comp-comp"
click v_levenshtein_sc_comp href "#form-levenshtein-sc-comp"
click v_levenshtein_sc href "#form-levenshtein-sc"
click v_damerau_levenshtein_ds_ds href "#form-damerau-levenshtein-ds-ds"
click v_damerau_levenshtein_sc href "#form-damerau-levenshtein-sc"
click v_hamming_comp_sc href "#form-hamming-comp-sc"
click v_hamming_sc href "#form-hamming-sc"
click v_jaro_winkler_sc href "#form-jaro-winkler-sc"
Types
Takes string · Gives number
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 · number — 34 operators in 7 blocks 🟢34
General purpose operators (1) 🟢1
Numeric operators (18) 🟢18
Time operators (2) 🟢2
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Data validation operators (2) 🟢2
Definitions (VTL-DL) (2) 🟢2
Goes to · operators that take any scalar — 48 operators in 8 blocks 🟢48
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Forms
string_distance(levenshtein, DS, DS) 🟢 · string → number
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
the Levenshtein distance between the measures of
DS_1andDS_2, which becomes the Number measurenum_var.- Manual:
String distances, Example 1, output verbatim: “Returns the Levenshtein distance, which is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another.” The measure is named by the Typical behaviours of the “Operators changing the data type”: “A default generic Measure is assigned by default to the result Data Set”.
- Expected:
num_varis 1 forfooandfo(delete oneo) and 1 forbarandbaz(substituterbyz); the page’s Result type,dataset { measure<number> _+ }, names no measure, and its Examples 1 and 2 givenum_var.
DS_r := string_distance(levenshtein, DS_1, DS_2);
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | foo |
| 2 | B | bar |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | fo |
| 2 | B | baz |
| Id_1 | Id_2 | num_var |
|---|---|---|
| 1 | A | 1 |
| 2 | B | 1 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
string_distance(levenshtein, DS, sc) 🟢 · string → number
Equal strings and null measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(levenshtein, DS_1, "fo"): a dataset and a scalar, with a value equal to the scalar and a null measure.- Manual:
String distances: “For operations at Data Set level, the input Data Sets must have exactly one string type Measure each.” The scalar is composed with it: “An operand Scalar value is composed with all the Measures of the other operand” (Typical behaviours).
- Expected:
num_varis 1 forfoo, 3 forbar, which shares no character withfo, and 0 forfo; the measure isnum_var, the default for a number (Typical behaviours, “Operators changing the data type”), as the page’s Result type names none. 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), as the manual’slengthandinstrexamples show.
DS_r := string_distance(levenshtein, DS_1, "fo");
| Id_1 | Me_1 |
|---|---|
| 1 | foo |
| 2 | bar |
| 3 | fo |
| 4 |
| Id_1 | num_var |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 0 |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
string_distance(levenshtein, sc, DS) 🟢 · string → number
Scalar first and null measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(levenshtein, "kitten", DS_1): the scalar first, the other order fromstring_distance(levenshtein, DS, sc); one measure is null.- Manual:
String distances: “All distance methods are symmetric (commutative), meaning that
string_distance(method, string1, string2)equalsstring_distance(method, string2, string1).”- Expected:
num_varis 3 forsitting, 0 forkittenand 1 formitten, the same as with the dataset first; the measure isnum_var, the default for a number (Typical behaviours, “Operators changing the data type”), as the page’s Result type names none. 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), as the manual’slengthandinstrexamples show.
DS_r := string_distance(levenshtein, "kitten", DS_1);
| Id_1 | Me_1 |
|---|---|
| 1 | sitting |
| 2 | kitten |
| 3 | mitten |
| 4 |
| Id_1 | num_var |
|---|---|
| 1 | 3 |
| 2 | 0 |
| 3 | 1 |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
string_distance(damerau_levenshtein, DS, DS) 🟢 · string → number
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
the Damerau-Levenshtein distance between the measures of
DS_1andDS_2, which becomes the Number measurenum_var.- Manual:
String distances, Example 2, output verbatim: “Returns the Damerau–Levenshtein distance, which extends Levenshtein distance by including transpositions of adjacent characters as a single operation.” The measure is named by the Typical behaviours of the “Operators changing the data type”: “A default generic Measure is assigned by default to the result Data Set”.
- Expected:
num_varis 1 forfooandfoand 1 forbarandbaz, the same as for Levenshtein, as neither pair has an adjacent transposition; the page’s Result type,dataset { measure<number> _+ }, names no measure, and its Examples 1 and 2 givenum_var.
DS_r := string_distance(damerau_levenshtein, DS_1, DS_2);
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | foo |
| 2 | B | bar |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | fo |
| 2 | B | baz |
| Id_1 | Id_2 | num_var |
|---|---|---|
| 1 | A | 1 |
| 2 | B | 1 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
string_distance(levenshtein, comp, comp) 🟢 · string → number
Kitten sitting and null 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(levenshtein, Me_1, Me_2)insidecalc, with a nullMe_2.- Manual:
String distances: “Returns the Levenshtein distance, which is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another.”
- Expected:
Me_3is 3 forkittenandsitting(substitutekbys,ebyi, insertg), 2 forflawandlawn(deletef, insertnat the end) and 0 forsameandsame, a new Number measure. 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), as the manual’slengthandinstrexamples show.
DS_r := DS_1[calc Me_3 := string_distance(levenshtein, Me_1, Me_2)];
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | kitten | sitting |
| 2 | flaw | lawn |
| 3 | same | same |
| 4 | abc |
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | kitten | sitting | 3 |
| 2 | flaw | lawn | 2 |
| 3 | same | same | 0 |
| 4 | abc |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
string_distance(levenshtein, sc, comp) 🟢 · string → number
Adjacent swap costs two 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(levenshtein, "fo", Me_1)insidecalc: the scalar first and the component second, the other order from Manual example 3 ofstring_distance(hamming, comp, sc).- Manual:
String distances: “Returns the Levenshtein distance, which is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another.”
- Expected:
the new Number measure
Me_2is 1 forfoo(insert oneo) and 2 forof(two substitutions): the swap of two adjacent characters is not one operation with Levenshtein, which onlydamerau_levenshteinallows;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), as the manual’slengthandinstrexamples show.
DS_r := DS_1[calc Me_2 := string_distance(levenshtein, "fo", Me_1)];
| Id_1 | Me_1 |
|---|---|
| 1 | foo |
| 2 | of |
| 3 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | foo | 1 |
| 2 | of | 2 |
| 3 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
string_distance(hamming, comp, sc) 🟢 · string → number
Manual example 3 🟢 pandas ✅ · DuckDB ✅
- Tests:
the Hamming distance between a component and a scalar, inside
calc.- Manual:
String distances, Example 3, output verbatim: “Returns the Hamming distance, which is the number of positions at which the corresponding characters are different. Both strings must have the same length.”
- Expected:
Me_2is 1 forfooandfob, which differ at the 3rd position only, and 3 forbarandfob, which differ at all three;Me_1is kept.
DS_r := DS_1[calc Me_2 := string_distance(hamming, Me_1, "fob")];
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | foo |
| 2 | B | bar |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | foo | 1 |
| 2 | B | bar | 3 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
string_distance(levenshtein, sc, sc) 🟢 · string → number
One deletion 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(levenshtein, SC_1, SC_2)withSC_1=fooandSC_2=fo, the Levenshtein distance of two scalars.- Manual:
String distances: “Returns the Levenshtein distance, which is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another.”, as in
string_distance(levenshtein, "foo", "fo")gives1.- Expected:
SC_ris 1, a Number: delete the lasto.
SC_r := string_distance(levenshtein, SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| foo | fo |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
string_distance(damerau_levenshtein, sc, sc) 🟢 · string → number
Adjacent transposition costs one 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(damerau_levenshtein, SC_1, SC_2)withSC_1=formandSC_2=from, two scalars that differ by an adjacent transposition.- Manual:
String distances: “Returns the Damerau–Levenshtein distance, which extends Levenshtein distance by including transpositions of adjacent characters as a single operation.”
- Expected:
SC_ris 1, a Number:orandrodiffer by one transposition, where Levenshtein would count two substitutions.
SC_r := string_distance(damerau_levenshtein, SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| form | from |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
string_distance(hamming, sc, sc) 🟢 · string → number
Three differing positions 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(hamming, SC_1, SC_2)withSC_1=karolinandSC_2=kathrin, two strings of the same length.- Manual:
String distances: “Returns the Hamming distance, which is the number of positions at which the corresponding characters are different. Both strings must have the same length.”
- Expected:
SC_ris 3, a Number:karolinandkathrinhave 7 characters and differ at the 3rd (randt), the 4th (oandh) and the 5th (landr).
SC_r := string_distance(hamming, SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| karolin | kathrin |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
string_distance(jaro_winkler, sc, sc) 🟢 · string → number
Identical strings 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(jaro_winkler, SC_1, SC_2)withSC_1=FOOandSC_2=FOO: two identical strings, one of the two cases whose distance needs no approximation, with Disjoint strings.- Manual:
String distances: “Returns the distance between two strings using the specified distance method”, and for
jaro_winkler“Returns the Jaro–Winkler distance, which is a string metric measuring an edit distance between two sequences”, with no formula and no value beyond “a value between0and1” for"FOO"and"BAR"; the Wikipedia article that it links says that “the distance is defined as the inversion of that value (distance = 1 − similarity)” (read on 2026-10-24).- Expected:
SC_ris 0, a Number: identical strings have a Jaro similarity of 1, which the Winkler prefix boost cannot raise, so the distance is 1 − 1.
SC_r := string_distance(jaro_winkler, SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| FOO | FOO |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
Disjoint strings 🟢 pandas ✅ · DuckDB ✅
- Tests:
string_distance(jaro_winkler, SC_1, SC_2)withSC_1=FOOandSC_2=BAR: two strings that have no character in common, the other case whose distance needs no approximation, with Identical strings.- Manual:
String distances:
string_distance(jaro_winkler, "FOO", "BAR")gives “a value between0and1”, andjaro_winkler“Returns the Jaro–Winkler distance, which is a string metric measuring an edit distance between two sequences”, with no formula; the Wikipedia article that it links says that “the distance is defined as the inversion of that value (distance = 1 − similarity)” (read on 2026-10-24).- Expected:
SC_ris 1, a Number: with no matching character the Jaro similarity is 0 (“If no matching characters are found then the strings are not similar”), and the Winkler boost, proportional to a common prefix of 0, adds nothing, so the distance is 1 − 0.
SC_r := string_distance(jaro_winkler, SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| FOO | BAR |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗