String length: length
Syntax
length ( op )
Input parameters
op |
the operand |
Examples of valid syntaxes
length("Hello, World!")
length(DS_1)
Semantics for scalar operations
Returns the length of a string. For example:
length("Hello, World!")
gives 13
length("")
gives 0
Input parameters type
op
dataset { measure<string> _+ }
| component<string>
| string
Result type
result
dataset { measure<integer[value >= 0]> int_var }
| component<integer[value >= 0]>
| integer[value >= 0]
Additional Constraints
For operations at Data Set level, the input Data Set must have exactly one string type Measure.
Behaviour
The operator has the behaviour of the “Operators changing the data type” (see the section “Typical behaviours of the ML Operators”). If op is a Data Set then length returns a dataset with a single measure int_var of type integer.
Examples
Given the operand dataset DS_1:
Input DS_1 (see structure)
Id_1 |
Id_2 |
Me_1 |
---|---|---|
1 |
A |
hello |
2 |
B |
Input DS_2 (see structure)
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
1 |
A |
hello |
world |
2 |
B |
hi |
Example 1
DS_r := length(DS_1);
results in (see structure):
Id_1 |
Id_2 |
int_var |
---|---|---|
1 |
A |
5 |
2 |
B |
0 |
Example 2
DS_r:= DS_1[calc Me_2:=length(Me_1)];
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
1 |
A |
hello |
5 |
2 |
B |
0 |
Example 3
DS_r := DS_2 [calc Me_10:= length(Me_1), Me_20:=length(Me_2)];
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
Me_2 |
Me_10 |
Me_20 |
---|---|---|---|---|---|
1 |
A |
hello |
world |
5 |
5 |
2 |
B |
hi |
0 |
2 |
Example 4
length operator applied at Data Set level to a multi Measure Data Set:
DS_r := length(DS_2)
would give error because DS_2 has more than one Measure.