Excerpt |
---|
Merges two or more columns of String type to generate output of String type. Optionally, you can insert a delimiter between the merged values. |
Info |
---|
NOTE: This function behaves exactly like the merge transform, although the syntax is different. See Merge Transform. |
String literal reference example:
D lang syntax |
---|
RawWrangle | true |
---|
Type | ref |
---|
showNote | true |
---|
WrangleText | derive type:single value:merge(['Hello,','World'],' ') as:'Hi' |
---|
|
merge(['Hello,','World'],' ') |
Output: Returnsthe value Hello, World
.
Column reference example:
D lang syntax |
---|
RawWrangle | true |
---|
Type | ref |
---|
showNote | true |
---|
WrangleText | derive type:single value:merge([string1,string2]) as:'merged_strings' |
---|
|
merge([string1,string2]) |
Output: Returns a single String value that is the merge of string1
and string2
values.
D lang syntax |
---|
RawWrangle | true |
---|
Type | syntax |
---|
showNote | true |
---|
WrangleText | derive type:single value:merge([string_ref1,string_ref2],'string_delim') |
---|
|
merge([string_ref1,string_ref2],'string_delim') |
Argument | Required? | Data Type | Description |
---|
string_ref1 | Y | string | Name of first column or first string literal to apply to the function |
string_ref2 | Y | string | Name of second column or second string literal to apply to the function |
string_delim | N | string | Optional delimiter string to insert between column or literal values |
string_ref1, string_ref2
String literal or name of the string column whose elements you want to merge together. You can merge together two or more strings.
Required? | Data Type | Example Value |
---|
Yes | String literal or column reference | myString1, myString2 |
string_delim
Optional string literal to insert between each string that is being merged.
Required? | Data Type | Example Value |
---|
No | String literal | '-' |
Example - Simple merge example
The following example contains the names of a set of American authors. You need to bring together these column values into a new column, called FullName
.
Source:
FirstName | LastName | MiddleInitial |
---|
Jack | Kerouac | L |
Paul | Theroux | E |
J.D. | Salinger | |
Philip | Dick | K |
Transformation:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'FullName' |
---|
Type | step |
---|
WrangleText | derive type:single value:merge([FirstName,MiddleInitial,LastName],' ') as:'FullName' |
---|
p01Name | Formula type |
---|
p01Value | Single row formula |
---|
p02Name | Formula |
---|
p02Value | merge([FirstName,MiddleInitial,LastName],' ') |
---|
p03Name | New column name |
---|
SearchTerm | New formula |
---|
|
Since the entry for J.D. Salinger has no middle name, you might want to add the following transformation:
D trans |
---|
RawWrangle | true |
---|
p03Value | '' |
---|
Type | step |
---|
WrangleText | replace col:FullName with:' ' on:' ' |
---|
p01Name | Column |
---|
p01Value | FullName |
---|
p02Name | Find |
---|
p02Value | ' ' |
---|
p03Name | Replace with |
---|
SearchTerm | Replace text or pattern |
---|
|
Results:
FirstName | LastName | MiddleInitial | FullName |
---|
Jack | Kerouac | L | Jack L Kerouac |
Paul | Theroux | E | Paul E Theroux |
J.D. | Salinger | | J.D. Salinger |
Philip | Dick | K | Philip K DIck |
Other Examples
While the syntax may be different, the MERGE
function behaves exactly like the merge
transform. For more examples, see Merge Transform.