Page tree

Trifacta Dataprep


Contents:

On April 28, 2021, Google is changing the required permissions for attaching IAM roles to service accounts. If you are using IAM roles for your Google service accounts, please see Changes to User Management.

   

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.

Wrangle vs. SQL: This function is part of Wrangle , a proprietary data transformation language. Wrangle is not SQL. For more information, see Wrangle Language.

Basic Usage

String literal example:

repeat('ha',3)

Output: Returns the string: hahaha.

Column reference example:

repeat(MyString,4)

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

Syntax and Arguments

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

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

Tip: For additional examples, see Common Tasks.

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

This page has no comments.