← replace operator page · string/replace/comp_patterns/patterns_from_components

Patterns from components 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

replace(Me_1, Me_2, Me_3) inside calc: both patterns come from components, a different pair for each data point.

Manual:

String pattern replacement types pattern1 and pattern2 as component<string> | string, and "Replaces all the occurrences of a specified string-pattern (pattern1) with another one (pattern2)."

Expected:

Me_4 is hello VTL, bANANa and abc: both an of banana are replaced, and x does not occur in abc. 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_4 := replace(Me_1, Me_2, Me_3)];

input/DS_1.csv ⇩

Id_1Me_1Me_2Me_3
1hello worldworldVTL
2bananaanAN
3abcxy
4ab

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Me_1Me_2Me_3Me_4
1hello worldworldVTLhello VTL
2bananaanANbANANa
3abcxyabc
4ab

expected/DS_r.json ⇩

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