Excerpt |
---|
Sets the data type of the specified column or columns. The column data is validated against the new data type, which can change the results of column profiling. |
Type is specified as a string literal or comma-separated set of literals. For more information on valid string literals, see Valid Data Type Strings .
Tips:
Tip |
---|
Tip: You can use the settype transform to override the data type inferred for a column. However, if a new transformation step is added, the column data type is re-inferred, which may override your specific typing. You should consider applying setttype transforms as late as possible in your recipes. |
- When a column is set to a data type, all values in the column are validated against the new type, which might change the number of mismatched values. Some cleanup might be required. Some operations might cause the data type to be re-validated automatically.
- It might be easier to set type using the column's drop-down. Selections of data type from the column drop-down are turned into recipe steps using the
settype
transform. - If you encounter a significant number of mismatches after you change the data type, you might find it helpful to change or revert the type to String. All data can be interpreted as a String or a list of string values. The transforms and functions for manipulating String data might be easier to use to clean up mismatched data before changing the data type to the preferred one.
- Row values that do not match the new data type might be turned to null values during job execution.
Single-column example:
D code |
---|
settype col: Score type: 'Integer' |
Output: Changes the data type for the Score
column to Integer.
Multi-column example:
D code |
---|
settype col: Score,studentId type: 'Integer' |
Output: Changes the data type for the Score
and studentId
columns to Integer.
D code |
---|
settype col:col1,col2 type:'string_literal' |
Token | Required? | Data Type | Description |
---|
settype | Y | transform | Name of the transform |
col | Y | string | Comma-separated list of columns to which to apply the specified type. |
type | Y | string | String literal identifying the data type to apply to the column(s). See Valid Data Type Strings. |
Identifies the column(s) to which to apply the transform. You can specify one or more columns.
Required? | Data Type |
---|
Yes | Comma-separated strings (column name or names) |
Include Page |
---|
| type Parameter |
---|
| type Parameter |
---|
|
D code |
---|
settype col: zips type:'Zipcode' |
Output: Changes the data type of the zips
column to Zip Code data type. All values are validated as U.S. Zip code.
Required? | Data Type |
---|
Yes | String value |
Source:
Here is a list of activities listed by date. Note the variation in date values, including what is clearly an invalid date. Here is the source data:
Code Block |
---|
myDate, myAction
4/4/2016,Woke up at 6:30
4-4-2016,Got ready
9-9-9999,Drove kids to school
4-4-2016, Commuted to work
|
Transformation:
When this data is imported into the Transformer page, there are couple of immediate issues: no column headings and blank rows at the bottom. These two transformations fix that:
D trans |
---|
RawWrangle | true |
---|
p03Value | 1 |
---|
Type | step |
---|
WrangleText | rename type: header method: index sourcerownumber: 1 |
---|
p01Name | Option |
---|
p01Value | Use row(s) as column names |
---|
p02Name | Type |
---|
p02Value | Use a single row to name columns |
---|
p03Name | Row number |
---|
SearchTerm | Rename column with row(s) |
---|
|
D trans |
---|
RawWrangle | true |
---|
p03Value | ismissing([myDate]) |
---|
Type | step |
---|
WrangleText | delete row: ismissing([myDate]) |
---|
p01Name | Condition |
---|
p01Value | Custom formula |
---|
p02Name | Type of formula |
---|
p02Value | Custom single |
---|
p03Name | Condition |
---|
p04Value | Delete matching rows |
---|
p04Name | Action |
---|
SearchTerm | Filter rows |
---|
|
For the invalid date, you can infer from the rows around it that it should be from the same date. You can make the following change to fix it:
D trans |
---|
RawWrangle | true |
---|
p03Value | '4-4-2016' |
---|
Type | step |
---|
WrangleText | replace col: myDate on: `9-9-9999` with: '4-4-2016' global: true |
---|
p01Name | Column |
---|
p01Value | myDate |
---|
p02Name | Find |
---|
p02Value | `9-9-9999` |
---|
p03Name | Replace with |
---|
p04Value | true |
---|
p04Name | Match all occurrences |
---|
SearchTerm | Replace text or pattern |
---|
|
Now that the dates look fairly consistent, you can set the data type of the column to a matching Datetime format:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'mm-dd-yy','mm*dd*yyyy' |
---|
Type | step |
---|
WrangleText | settype col: myDate type: 'Datetime','mm-dd-yy','mm*dd*yyyy' |
---|
p01Name | Columns |
---|
p01Value | myDate |
---|
p02Name | New type |
---|
p02Value | Custom or Date/Time |
---|
p03Name | Specify type |
---|
SearchTerm | Change column data type |
---|
|
Note the syntax above for specifying Datetime types. In addition to the Datetime
keyword, you must specify the format type, followed by the variation of that format.
Tip |
---|
Tip: A set of supported formats and variations for Datetime are available through the column data type selector. When you select your desired Datetime format, the setttype transform is added to your recipe. |
Results:
myDate | myAction |
---|
4/4/2016 | Woke up at 6:30 |
4-4-2016 | Got ready |
4-4-2016 | Drove kids to school |
4-4-2016 | Commuted to work |
Include Page |
---|
| EXAMPLE - Change data type transformation |
---|
| EXAMPLE - Change data type transformation |
---|
|
D s also |
---|
label | wrangle_transform_settype |
---|
|