← length operator page · string/length/ds/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

length(DS_1) on a dataset with one String measure, which becomes the Integer measure int_var; one value is null.

Manual:

String length, Example 1, output verbatim: "Returns the length of a string." For a data set, "length returns a dataset with a single measure int_var of type integer."

Expected:

int_var is 5 for hello and 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).

script.vtl ⇩

DS_r := length(DS_1);

input/DS_1.csv ⇩

Id_1Id_2Me_1
1Ahello
2B

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "String", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2int_var
1A5
2B

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Id_2", "type": "String", "role": "Identifier"},
        {"name": "int_var", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}