Page tree



Contents:

The cloud-based version of Trifacta Wrangler is now available! Read all about it, and register for your free account.

Contents:


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.

Basic Usage

String literal example:

Output: Returns the string: hahaha.

Column reference example:

Output: Returns the values of the MyString column value written four times in a row. 

Syntax


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

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

Usage Notes:

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

Examples

Example - REPEAT string function

Source:

myStrrepeat_count
ha0
ha1
ha1.5
ha2
ha-2

 

Transformation:

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula repeat(myStr,repeat_count)
Parameter: New column name 'repeat_string'

Results:

myStrrepeat_countrepeat_string
ha0 
ha1ha
ha1.5 
ha2haha
ha-2 

Example - Padding values

In the following example, the imported prodId values are supposed to be eight characters in length. Somewhere during the process, however, leading 0 characters were truncated. The steps below allow you to re-insert the leading characters.

Source:

prodNameprodId
w011
w0210000001
w03345
w0410402

Transformation:

First, we need to identify how many zeroes need to be inserted for each prodId:

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula 8 - len(prodId)
Parameter: New column name 'len_prodId'

Use the REPEAT function to generate a pad string based on the above values:

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula repeat('0', len_prodId)
Parameter: New column name 'padString'

Merge the pad string and the original prodId column:

Transformation Name Merge columns
Parameter: Columns padString,prodId
Parameter: Separator ''
Parameter: New column name 'column2'

Results:

When you delete the intermediate columns and rename column2 to prodId, you have the following table:

prodNameprodId
w0100000001
w0210000001
w0300000345
w0400010402

Your Rating: Results: 1 Star2 Star3 Star4 Star5 Star 11 rates

This page has no comments.