Field Type Converter
The Field Type Converter processor converts the data types of fields to compatible data types. You might use the processor to convert the data types of fields before performing calculations. You can also use the processor to change the scale of decimal data.
You configure the processor to use one of the following methods to convert data types:
- By Field Name
-
Convert the data type of a field with the specified name. For example, you can convert a field named
dropoff_datetime
with the String data type to the Date data type.You can specify individual field names or use field path expressions to specify sets of fields to convert.
- By Data Type
-
Convert the data type of all fields with the specified type. For example, you can convert all fields with the Decimal data type to the String data type.
You can convert data types by field name or by data type. You cannot use both methods in the same stage.
Configure the conversion for an appropriate, compatible data type. Consider the actual data in the field as well, since even valid conversions can truncate data. For example, converting a field from Integer to Decimal is valid. Converting a field from Decimal to Integer is also valid, but the conversion can truncate any decimal values in the data.
Valid Type Conversions
The following table lists the data types that can be converted to another data type. List, Map, and List-Map data types cannot be converted.
Target Data Type | Source Data Type |
---|---|
Boolean | Byte, Decimal, Double, Float, Integer, Long, Short, String |
Byte | Decimal, Double, Float, Integer, Long, Short, String |
Byte Array | String |
Character | String |
Date | Datetime, Long, String, Time |
Datetime | Date, Long, String |
Decimal | Byte, Double, Float, Integer, Long, Short, String |
Double | Byte, Decimal, Integer, Float, Long, Short, String |
Float | Byte, Decimal, Double, Integer, Long, Short, String |
Integer | Boolean1, Byte, Decimal, Double, Float, Long, Short, String |
Long | Boolean1, Byte, Date, Datetime, Decimal, Double, Float, Integer, Short, String |
Short | Boolean1, Byte, Decimal, Double, Float, Integer, Long, String |
String | All supported data types except List, Map, and List-Map |
Time | Date, Datetime, String, Long |
Zoned Datetime | Date, Datetime, String |
Expressions to Convert by Field Name
When converting data types by field name, you can specify field path expressions to specify sets of fields to convert.
Column Name | Data Type | Precision | Scale |
order_id
|
Number
|
8
|
0
|
The JDBC Query Consumer origin converts all Oracle columns with the Number data type to the Decimal data type, storing the precision and scale for the column in field attributes. You'd like to use the Field Type Converter processor to convert each field with the Decimal data type to the Integer, Long, or Float data type, based on the precision and scale of the field.
Instead of specifying each field name to convert the field to the appropriate data type, you can use field path expressions to specify sets of fields to convert.
For example, the following field path expression returns all decimal fields with a scale of 0 and a precision less than 10, which you can then convert to the Integer data type:
/*[${f:attribute('scale') == 0 && f:attribute('precision') < 10
}]
The following field path expression returns all decimal fields with a scale of 0 and a precision greater than or equal to 10, which you can then convert to the Long data type:
/*[${f:attribute('scale') == 0 && f:attribute('precision') >= 10
}]
And the following field path expression returns all decimal fields with a scale greater than 0, which you can then convert to the Float data type:
/*[${f:attribute('scale') > 0}]
You specify these field path expressions when you configure the Field Type Converter processor, as follows:
Changing the Scale of Decimal Fields
You can use the Field Type Converter processor to change the scale of decimal fields. For example, you might have a decimal field with the value 12345.6789115, and you'd like to decrease the scale to 4 so that the value is 12345.6789.
To change the scale, you configure the processor to convert decimal fields to the Decimal data type, specifying the scale to use. When you decrease the scale, you can also specify the rounding strategy. For example, you can configure the processor to round up or round down.
You can change the scale of a decimal field by name. Or you can change the scale for all fields with the Decimal data type.