Contents:
- Since the
REPEAT
function matches based on fixed numeric values, changes to the length or structure of a data field can cause your recipe to fail to properly execute. - The
REPEAT
function requires an integer value for the number of characters to match.
Basic Usage
String literal example:
derive type:single value:REPEAT('ha',3)
Output: The string hahaha
is written to the new column.
Column reference example:
derive type:single value:REPEAT(MyString,4)
Output: The values of the MyString
column value are written four times in a row to the new column.
Syntax and Arguments
derive type:single value:REPEAT(column_string,rpt_count)
Argument | Required? | Data Type | Description |
---|---|---|---|
column_string | Y | string | Name of the column or string literal to be applied to the function |
rpt_count | N | integer (positive) | Count of times to repeat the string |
For more information on syntax standards, see Language Documentation Syntax Notes.
column_string
Name of the column or String literal to be repeated.
- Missing string or column values generate missing string results.
- String constants must be quoted (
'Hello, World'
). - Multiple columns and wildcards are not supported.
Usage Notes:
Required? | Data Type | Example Value |
---|---|---|
Yes | String literal, function, or column reference | myColumn |
rpt_count
Count of times to repeat the string.
- If the value is not specified, the default is
1
. - Value must a non-negative integer.
- References to columns of integer data type are not supported.
Usage Notes:
Required? | Data Type | Example Value |
---|---|---|
No | Integer (non-negative) | 5 |
Tip: For additional examples, see Common Tasks.
Examples
Example - REPEAT string function
Source:
myStr | repeat_count |
---|---|
ha | 0 |
ha | 1 |
ha | 1.5 |
ha | 2 |
ha | -2 |
Transform:
derive type:single value:REPEAT(myStr,repeat_count) as:'repeat_string'
Results:
myStr | repeat_count | repeat_string |
---|---|---|
ha | 0 | |
ha | 1 | ha |
ha | 1.5 | |
ha | 2 | haha |
ha | -2 |
Example - padding a string
In this example, the prodId values are supposed to be 8 characters in length. Somewhere in the analytics pipeline, the leading 0's were stripped. The following steps add them back.
Source:
prodName | prodId |
---|---|
w01 | 1 |
w02 | 10000001 |
w03 | 345 |
w04 | 10402 |
Transform:
First, you must calculate how many leading 0's need to be added back for each line:
derive type:single value: 8 - LEN(prodId) as:'lenPad'
Build the pad string based on the above value:
derive type:single value:REPEAT('0',lenPad) as:'padString'
Combine the above string with the prodId value:
merge col: string,repeat_count as: 'column1'
Results:
After you remove the intermediate columns and rename column1
to prodId
, you should have the following:
prodName | prodId |
---|---|
w01 | 00000001 |
w02 | 10000001 |
w03 | 00000345 |
w04 | 00010402 |
This page has no comments.