← instr operator page · string/instr/comp_pattern/manual_ex_3

Manual example 3 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

two instr calls in one calc on DS_2, where Me_1 is null in one data point.

Manual:

String pattern location, Example 3, output verbatim: "If the nth occurrence of the string-pattern after the start th character is not found in the input string, the returned value is 0."

Expected:

Me_10 is 5 and null, and Me_20 is 2 and 0: hi has no o, so its position is 0, while the null Me_1 gives null. 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 := DS_2 [calc Me_10:= instr(Me_1, "o" ), Me_20:=instr(Me_2, "o")];

input/DS_2.csv ⇩

Id_1Id_2Me_1Me_2
1Ahelloworld
2Bhi

input/DS_2.json ⇩

{
  "datasets": [
    {
      "name": "DS_2",
      "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},
        {"name": "Me_2", "type": "String", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Me_1Me_2Me_10Me_20
1Ahelloworld52
2Bhi0

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Id_2", "type": "String", "role": "Identifier"},
        {"name": "Me_1", "type": "String", "role": "Measure"},
        {"name": "Me_2", "type": "String", "role": "Measure"},
        {"name": "Me_10", "type": "Integer", "role": "Measure"},
        {"name": "Me_20", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}