String pattern location · instr
---
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 pattern location · instr<br/>🟢8"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds_pattern["instr(DS, pattern)"]:::ok
v_ds_pattern_start["instr(DS, pattern, start)"]:::ok
v_ds_pattern_start_occ["instr(DS, pattern, start, occurrence)"]:::ok
v_ds_placeholder_occ["instr(DS, pattern, _, occurrence)"]:::ok
v_ds_pattern_start_placeholder["instr(DS, pattern, start, _)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp_pattern["instr(comp, pattern)"]:::ok
v_comp_params["instr(comp, comp, comp, comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc_pattern["instr(sc, pattern)"]:::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_ds_pattern href "#form-ds-pattern"
click v_ds_pattern_start href "#form-ds-pattern-start"
click v_ds_pattern_start_occ href "#form-ds-pattern-start-occ"
click v_ds_placeholder_occ href "#form-ds-placeholder-occ"
click v_ds_pattern_start_placeholder href "#form-ds-pattern-start-placeholder"
click v_comp_pattern href "#form-comp-pattern"
click v_comp_params href "#form-comp-params"
click v_sc_pattern href "#form-sc-pattern"
Types
Takes integer, string · Gives integer
Comes from · integer, string — 27 operators in 6 blocks 🟢27
General purpose operators (2) 🟢2
String operators (9) 🟢9
Numeric operators (4) 🟢4
Time operators (7) 🟢7
Aggregate and Analytic operators (2) 🟢2
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
Goes to · integer — 43 operators in 8 blocks 🟢43
General purpose operators (1) 🟢1
String operators (1) 🟢1
Numeric operators (18) 🟢18
Time operators (6) 🟢6
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (10) 🟢10
Data validation operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 46 operators in 8 blocks 🟢46
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (8) 🟢8
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Forms
instr(DS, pattern) 🟢 · string → integer
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
instr(DS_1, "hello")on a dataset with one String measure: the position ofhelloin 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, “instrreturns a dataset with a single measureint_varof typeinteger.”- Expected:
int_varis 1 forhello world, 5 forsay helloand for"hi, hello! ", and 0 forhe, wherehellois not found and “the returned value is 0”.
DS_r:= instr(DS_1,"hello");
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | hello world |
| 2 | A | say hello |
| 3 | A | he |
| 4 | A | hi, hello! |
| Id_1 | Id_2 | int_var |
|---|---|---|
| 1 | A | 1 |
| 2 | A | 5 |
| 3 | A | 0 |
| 4 | A | 5 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
instr(DS, pattern, start) 🟢 · string, integer → integer
Matches before start skipped 🟢 pandas ✅ · DuckDB ✅
- Tests:
instr(DS_1, "o", 6): the search starts at the 6th character, so earlier matches do not count; one measure is null.- Manual:
String pattern location: “The search starts from the startth character of the input string and finds the nth occurrence of the pattern, returning the position of its first character.”
- Expected:
int_var, the page’s measure for a data set result, is 8, 0 and 6: theoat 5 ofhello worldis before the 6th character, bothoofboot campare before it, and theoofabcdeois at the start position, which counts as withstartomitted: “the search starts from the 1st position”. 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’slengthandinstrexamples show.
DS_r := instr(DS_1, "o", 6);
| Id_1 | Me_1 |
|---|---|
| 1 | hello world |
| 2 | boot camp |
| 3 | abcdeo |
| 4 |
| Id_1 | int_var |
|---|---|
| 1 | 8 |
| 2 | 0 |
| 3 | 6 |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
instr(DS, pattern, start, occurrence) 🟢 · string, integer → integer
Second occurrence from start 🟢 pandas ✅ · DuckDB ✅
- Tests:
instr(DS_1, "o", 2, 2): the secondofrom the 2nd character; one measure is null.- Manual:
String pattern location: “The search starts from the startth character of the input string and finds the nth occurrence of the pattern, returning the position of its first character.”
- Expected:
int_var, the page’s measure for a data set result, is 8, 5 and 0:o-o-ohas itsoat 1, 3 and 5, and the one at 1 is before the 2nd character, so the second found is at 5 (it would be 3 ifstartwere ignored);hellohas no secondo. 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’slengthandinstrexamples show.
DS_r := instr(DS_1, "o", 2, 2);
| Id_1 | Me_1 |
|---|---|
| 1 | hello world |
| 2 | o-o-o |
| 3 | hello |
| 4 |
| Id_1 | int_var |
|---|---|
| 1 | 8 |
| 2 | 5 |
| 3 | 0 |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
instr(DS, pattern, _, occurrence) 🟢 · string, integer → integer
Placeholder for start 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_forstartininstr(DS_1, "o", _, 2): the secondofrom the 1st position.- Manual:
String pattern location: “If
startis omitted, the search starts from the 1st position.” Its valid syntaxes includeinstr ( DS_1, "ab", _ , 2 ).- Expected:
int_var, the page’s measure for a data set result, is 8, 3 and 0: the secondoofhello worldis at 8 and that ofo-o-oat 3, andhellohas oneoonly. 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’slengthandinstrexamples show.
DS_r := instr(DS_1, "o", _, 2);
| Id_1 | Me_1 |
|---|---|
| 1 | hello world |
| 2 | o-o-o |
| 3 | hello |
| 4 |
| Id_1 | int_var |
|---|---|
| 1 | 8 |
| 2 | 3 |
| 3 | 0 |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
instr(DS, pattern, start, _) 🟢 · string, integer → integer
Placeholder for occurrence 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_foroccurrence:instr(DS_1, "o", 2, _)isinstr(DS_1, "o", 2)with the underscore written out.- Manual:
In the invocation, a non-specified optional operand “is substituted by an underscore or, if it is in the end of the invocation, can be omitted” (Overview and conventions, syntax conventions); String pattern location: “If nth
occurrenceis omitted, the value is 1.”- Expected:
the first
ofrom the 2nd character:int_var, the page’s measure for a data set result, is 5, 3 and 0, as theoat 1 ofo-ois before the 2nd character andabchas 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’slengthandinstrexamples show.
DS_r := instr(DS_1, "o", 2, _);
| Id_1 | Me_1 |
|---|---|
| 1 | hello world |
| 2 | o-o |
| 3 | abc |
| 4 |
| Id_1 | int_var |
|---|---|
| 1 | 5 |
| 2 | 3 |
| 3 | 0 |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
instr(comp, pattern) 🟢 · string → integer
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
instr(Me_1, "hello")insidecalc, where the new measureMe_2takes the position.- Manual:
String pattern location, Example 2, output verbatim: “The operator returns the position in the input string of a specified string (
pattern).”- Expected:
Me_2is 1, 5, 0 and 5;Me_1is kept.
DS_r := DS_1[calc Me_2:=instr(Me_1,"hello")];
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | hello world |
| 2 | A | say hello |
| 3 | A | he |
| 4 | A | hi, hello! |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | hello world | 1 |
| 2 | A | say hello | 5 |
| 3 | A | he | 0 |
| 4 | A | hi, hello! | 5 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Manual example 3 🟢 pandas ✅ · DuckDB ✅
- Tests:
two
instrcalls in onecalconDS_2, whereMe_1is null in one data point.- Manual:
String pattern location, Example 3, output verbatim: “If the nth
occurrenceof the string-pattern after thestartth character is not found in the input string, the returned value is 0.”- Expected:
Me_10is 5 and null, andMe_20is 2 and 0:hihas noo, so its position is 0, while the nullMe_1gives 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).
DS_r := DS_2 [calc Me_10:= instr(Me_1, "o" ), Me_20:=instr(Me_2, "o")];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | hello | world |
| 2 | B | hi |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_10 | Me_20 |
|---|---|---|---|---|---|
| 1 | A | hello | world | 5 | 2 |
| 2 | B | hi | 0 |
Files: script.vtl · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
instr(comp, comp, comp, comp) 🟢 · string, integer → integer
Pattern and start from components 🟢 pandas ✅ · DuckDB ✅
- Tests:
instr(Me_1, Me_2, Me_3)insidecalc:patternandstartcome from components, andoccurrenceis left out.- Manual:
String pattern location types
patternascomponent<string> | stringandstartascomponent<integer [value >= 1]> | integer [value >= 1], and “If nthoccurrenceis omitted, the value is 1.”- Expected:
Me_4is 8 forofrom the 6th character ofhello world, 4 foranfrom the 3rd ofbananaand 7 forwfrom the 7th ofhello world, where thewis at the start position. 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’slengthandinstrexamples show.
DS_r := DS_1[calc Me_4 := instr(Me_1, Me_2, Me_3)];
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | hello world | o | 6 |
| 2 | banana | an | 3 |
| 3 | hello world | w | 7 |
| 4 | a | 1 |
| Id_1 | Me_1 | Me_2 | Me_3 | Me_4 |
|---|---|---|---|---|
| 1 | hello world | o | 6 | 8 |
| 2 | banana | an | 3 | 4 |
| 3 | hello world | w | 7 | 7 |
| 4 | a | 1 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
All parameters from components 🟢 pandas ✅ · DuckDB ✅
- Tests:
instr(Me_1, Me_2, Me_3, Me_4)insidecalc:pattern,startandoccurrenceall come from components.- Manual:
String pattern location types
occurrenceascomponent<integer [value >= 1]> | integer [value >= 1], and “If the nthoccurrenceof the string-pattern after thestartth character is not found in the input string, the returned value is 0.”- Expected:
Me_5is 8, 4, 5 and 0: the 2ndoofhello worldis at 8,anfrom the 3rd character ofbananaat 4, the 3rdoofo-o-oat 5, andhellohas no 2ndo.
DS_r := DS_1[calc Me_5 := instr(Me_1, Me_2, Me_3, Me_4)];
| Id_1 | Me_1 | Me_2 | Me_3 | Me_4 |
|---|---|---|---|---|
| 1 | hello world | o | 1 | 2 |
| 2 | banana | an | 3 | 1 |
| 3 | o-o-o | o | 1 | 3 |
| 4 | hello | o | 1 | 2 |
| Id_1 | Me_1 | Me_2 | Me_3 | Me_4 | Me_5 |
|---|---|---|---|---|---|
| 1 | hello world | o | 1 | 2 | 8 |
| 2 | banana | an | 3 | 1 | 4 |
| 3 | o-o-o | o | 1 | 3 | 5 |
| 4 | hello | o | 1 | 2 | 0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
instr(sc, pattern) 🟢 · string → integer
Pattern at the third position 🟢 pandas ✅ · DuckDB ✅
- Tests:
instr(SC_1, SC_2)withSC_1=abcdeandSC_2=c, a scalar with onlypattern.- Manual:
String pattern location: “The operator returns the position in the input string of a specified string (
pattern).”, as ininstr ("abcde", "c" )gives3.- Expected:
SC_ris 3, an Integer:cis the 3rd character ofabcde.
SC_r := instr(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| abcde | c |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗