← instr operator page · string/instr/ds_pattern/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

instr(DS_1, "hello") on a dataset with one String measure: the position of hello in each value.

Manual:

String pattern location, Example 1, output verbatim: "The operator returns the position in the input string of a specified string ( pattern )." For a data set, "instr returns a dataset with a single measure int_var of type integer."

Expected:

int_var is 1 for hello world, 5 for say hello and for "hi, hello! ", and 0 for he, where hello is not found and "the returned value is 0".

script.vtl ⇩

DS_r:= instr(DS_1,"hello");

input/DS_1.csv ⇩

Id_1Id_2Me_1
1Ahello world
2Asay hello
3Ahe
4Ahi, hello!

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
1A1
2A5
3A0
4A5

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"}
      ]
    }
  ]
}