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 r085
Excerpt

Evaluates an input against the String datatype. If the input matches, the function outputs a String value. Input can be a literal, a column of values, or a function returning values. Values can be of any data type.

After you have converted your values to strings, if a sufficient percentage of inputs from a column are successfully converted to the other data type, the column may be retyped. 

Tip

Tip: If the column is not automatically retyped as a result of this function, you can manually set the type to String in a subsequent recipe step.

D s lang vs sql

D s
snippetBasic

D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value: parsestring(strInput) as: 'convertedString'

parsestring(strInput)

Output: Returns the String data type value for strInput values.

D s
snippetSyntax

D lang syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value:parsestring(str_input)

parsestring(str_input)


ArgumentRequired?Data TypeDescription
str_inputYanyLiteral, name of a column, or a function returning values to match

D s lang notes

str_input

Literal, column name, or function returning values that are to be evaluated for conversion to String values.

  • Missing values for this function in the source data result in null values in the output.
  • Multiple columns and wildcards are not supported.

D s
snippetusage


Required?Data TypeExample Values
Yesany

5

"Porsche"

3.4


D s
snippetExamples

Example - type parsing functions

Source:

The following table contains values for city, state, and zip code for locations in the United States:

CityStateZip
San FranciscoCA94105
SeattleWA98109
PortlandOR97202
San DiegoCA92109
BrooklynNY11203
PortlandME4101
BostonMA2170

In the above table, you can see that some of the values are listed as four-digit zip codes, which are invalid. These values are likely to be interpreted as Integer values, which means that any leading zeroes are dropped. You can use the steps below to fix it.

Transformation:

Since you are working with integer values, you can use the following transformation to test the length of the values as if they were strings using the PARSESTRING function. If the values are only four characters long, then the value is merged with a leading 0:

D trans
RawWrangletrue
Typestep
WrangleTextset col: Zip value: if(len(parsestring($col)) == 4, merge(['0',parsestring($col)]), $col)
p01NameColumns
p01ValueZip
p02NameFormula
p02Valueif(len(parsestring($col)) == 4, merge(['0',parsestring($col)]), $col)
SearchTermEdit column with formula

 The $col reference points to the column that has been selected to be edited. In this case, that column is Zip. For more information, see Source Metadata References.

Depending on the number of rows in your dataset, the 

D s webapp
 may not re-infer the data as Zip type. You can use the following transformation to change the data type for the column to Zip:

D trans
RawWrangletrue
Typestep
WrangleTextsettype col: Zip type: Zipcode
p01NameColumns
p01ValueZip
p02NameNew type
p02ValueZipcode
SearchTermChange column data type

Results:

CityStateZip
San FranciscoCA94105
SeattleWA98109
PortlandOR97202
San DiegoCA92109
BrooklynNY11203
PortlandME04101
BostonMA02170

D s also
labeltype