Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version next

...

D s
snippetBasic

String literal example:

D code

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

...

Output: Returns the string: hahaha.

Column reference example:

D code

derive type:single value:REPEAT(MyString,4)

Output:

...

Returns the values of the MyString column value

...

written four times in a row

...

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

...

myStrrepeat_count
ha0
ha1
ha1.5
ha2
ha-2

 

TransformTransformation:

d-

...

trans
RawWrangletrue
p03Value'repeat_string'
Typestep
WrangleTextderive type:single value:

...

repeat(myStr,repeat_count) as:'repeat_string'

 

p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuerepeat(myStr,repeat_count)
p03NameNew column name
SearchTermNew formula

Results:

myStrrepeat_countrepeat_string
ha0 
ha1ha
ha1.5 
ha2haha
ha-2 

Example -

...

Padding values

In this the following example, the imported prodId values  values are supposed to be 8 eight characters in length. Somewhere in during the analytics pipeline, the leading 0's were stripped. The following steps add them backprocess, however, leading 0 characters were truncated. The steps below allow you to re-insert the leading characters.

Source:

prodNameprodId
w011
w0210000001
w03345
w0410402

TransformTransformation:

First, you must calculate we need to identify how many leading 0's zeroes need to be added back inserted for each lineprodId:

d-

...

trans
RawWrangletrue
p03Value'len_prodId'
Typestep
WrangleTextderive type:single value: 8 -

...

len(prodId) as: '

...

Build the

len_prodId'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Value8 - len(prodId)
p03NameNew column name
SearchTermNew formula

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

d-

...

trans
RawWrangletrue
p03Value'padString'
Typestep
WrangleTextderive type:single value:

...

repeat('0',

...

len_prodId) as: 'padString'
Combine the above string with the prodId value
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuerepeat('0', len_prodId)
p03NameNew column name
SearchTermNew formula

Merge the pad string and the original prodId column:

d-

...

trans
RawWrangletrue
p03Value'column2'
Typestep
WrangleTextmerge col:

...

padString,

...

prodId as: '

...

column2'
p01NameColumns
p01ValuepadString,prodId
p02NameSeparator
p02Value''
p03NameNew column name
SearchTermMerge columns

Results:

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

prodNameprodId
w0100000001
w0210000001
w0300000345
w0400010402

D s also
labelstring