String distances · string_distance

🟢 11 of 11 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["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

Viral attributes: combined with the propagation rules → Viral propagation

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
Clause operators (9) 🟢9
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
Clause operators (9) 🟢9

Forms

string_distance(levenshtein, DS, DS) 🟢 · string → number

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

the Levenshtein distance between the measures of DS_1 and DS_2, which becomes the Number measure num_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_var is 1 for foo and fo (delete one o) and 1 for bar and baz (substitute r by z); the page’s Result type, dataset { measure<number> _+ }, names no measure, and its Examples 1 and 2 give num_var.

script.vtl
DS_r := string_distance(levenshtein, DS_1, DS_2);
Input DS_1
Id_1Id_2Me_1
1Afoo
2Bbar
Input DS_2
Id_1Id_2Me_1
1Afo
2Bbaz
Expected DS_r
Id_1Id_2num_var
1A1
2B1

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_var is 1 for foo, 3 for bar, which shares no character with fo, and 0 for fo; the measure is num_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’s length and instr examples show.

script.vtl
DS_r := string_distance(levenshtein, DS_1, "fo");
Input DS_1
Id_1Me_1
1foo
2bar
3fo
4
Expected DS_r
Id_1num_var
11
23
30
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 from string_distance(levenshtein, DS, sc); one measure is null.

Manual:

String distances: “All distance methods are symmetric (commutative), meaning that string_distance(method, string1, string2) equals string_distance(method, string2, string1).”

Expected:

num_var is 3 for sitting, 0 for kitten and 1 for mitten, the same as with the dataset first; the measure is num_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’s length and instr examples show.

script.vtl
DS_r := string_distance(levenshtein, "kitten", DS_1);
Input DS_1
Id_1Me_1
1sitting
2kitten
3mitten
4
Expected DS_r
Id_1num_var
13
20
31
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_1 and DS_2, which becomes the Number measure num_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_var is 1 for foo and fo and 1 for bar and baz, 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 give num_var.

script.vtl
DS_r := string_distance(damerau_levenshtein, DS_1, DS_2);
Input DS_1
Id_1Id_2Me_1
1Afoo
2Bbar
Input DS_2
Id_1Id_2Me_1
1Afo
2Bbaz
Expected DS_r
Id_1Id_2num_var
1A1
2B1

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) inside calc, with a null Me_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_3 is 3 for kitten and sitting (substitute k by s, e by i, insert g), 2 for flaw and lawn (delete f, insert n at the end) and 0 for same and same, 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’s length and instr examples show.

script.vtl
DS_r := DS_1[calc Me_3 := string_distance(levenshtein, Me_1, Me_2)];
Input DS_1
Id_1Me_1Me_2
1kittensitting
2flawlawn
3samesame
4abc
Expected DS_r
Id_1Me_1Me_2Me_3
1kittensitting3
2flawlawn2
3samesame0
4abc

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) inside calc: the scalar first and the component second, the other order from Manual example 3 of string_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_2 is 1 for foo (insert one o) and 2 for of (two substitutions): the swap of two adjacent characters is not one operation with Levenshtein, which only damerau_levenshtein allows; Me_1 is 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’s length and instr examples show.

script.vtl
DS_r := DS_1[calc Me_2 := string_distance(levenshtein, "fo", Me_1)];
Input DS_1
Id_1Me_1
1foo
2of
3
Expected DS_r
Id_1Me_1Me_2
1foo1
2of2
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_2 is 1 for foo and fob, which differ at the 3rd position only, and 3 for bar and fob, which differ at all three; Me_1 is kept.

script.vtl
DS_r := DS_1[calc Me_2 := string_distance(hamming, Me_1, "fob")];
Input DS_1
Id_1Id_2Me_1
1Afoo
2Bbar
Expected DS_r
Id_1Id_2Me_1Me_2
1Afoo1
2Bbar3

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) with SC_1 = foo and SC_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") gives 1.

Expected:

SC_r is 1, a Number: delete the last o.

script.vtl
SC_r := string_distance(levenshtein, SC_1, SC_2);
Input scalars
SC_1SC_2
foofo
Expected scalars

Name

Type

Value

SC_r

Number

1

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) with SC_1 = form and SC_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_r is 1, a Number: or and ro differ by one transposition, where Levenshtein would count two substitutions.

script.vtl
SC_r := string_distance(damerau_levenshtein, SC_1, SC_2);
Input scalars
SC_1SC_2
formfrom
Expected scalars

Name

Type

Value

SC_r

Number

1

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) with SC_1 = karolin and SC_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_r is 3, a Number: karolin and kathrin have 7 characters and differ at the 3rd (r and t), the 4th (o and h) and the 5th (l and r).

script.vtl
SC_r := string_distance(hamming, SC_1, SC_2);
Input scalars
SC_1SC_2
karolinkathrin
Expected scalars

Name

Type

Value

SC_r

Number

3

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) with SC_1 = FOO and SC_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 between 0 and 1” 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_r is 0, a Number: identical strings have a Jaro similarity of 1, which the Winkler prefix boost cannot raise, so the distance is 1 − 1.

script.vtl
SC_r := string_distance(jaro_winkler, SC_1, SC_2);
Input scalars
SC_1SC_2
FOOFOO
Expected scalars

Name

Type

Value

SC_r

Number

0

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) with SC_1 = FOO and SC_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 between 0 and 1”, and jaro_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_r is 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.

script.vtl
SC_r := string_distance(jaro_winkler, SC_1, SC_2);
Input scalars
SC_1SC_2
FOOBAR
Expected scalars

Name

Type

Value

SC_r

Number

1

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