Repeats a string a specified number of times. The string can be specified as a String literal, a function returning a String, or a column reference.

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. 

derive type:single value:REPEAT(column_string,rpt_count)

ArgumentRequired?Data TypeDescription
column_stringYstringName of the column or string literal to be applied to the function
rpt_countNinteger (positive)Count of times to repeat the string

column_string

Name of the column or String literal to be repeated.

Required?Data TypeExample Value
YesString literal, function, or column referencemyColumn

rpt_count

Count of times to repeat the string.

Required?Data TypeExample Value
NoInteger (non-negative)5

Example - REPEAT string function

Source:

myStrrepeat_count
ha0
ha1
ha1.5
ha2
ha-2

 

Transform:

derive type:single value:REPEAT(myStr,repeat_count) as:'repeat_string'

 

Results:

myStrrepeat_countrepeat_string
ha0 
ha1ha
ha1.5 
ha2haha
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:

prodNameprodId
w011
w0210000001
w03345
w0410402

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:

prodNameprodId
w0100000001
w0210000001
w0300000345
w0400010402