Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

D toc
Excerpt

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.

  • 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.

D s
snippetBasic

String literal example:

D code

derive type:single value:REPEAT('ha',3)

Output: The string hahaha is written to the new column.

Column reference example:

D code

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. 

D s
snippetSyntax

D code

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

D s lang 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.

D s
snippetusage

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

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.

D s
snippetusage

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

D s
snippetExamples

Example - REPEAT string function

Source:

myStrrepeat_count
ha0
ha1
ha1.5
ha2
ha-2

 

Transform:

D code

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:

D code

derive type:single value: 8 - LEN(prodId) as:'lenPad'

Build the pad string based on the above value:
D code

derive type:single value:REPEAT('0',lenPad) as:'padString'

Combine the above string with the prodId value:
D code

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


D s also
labelstring